Nail Disease Classification
Transfer Learning with EfficientNet-B0
An image classification project using EfficientNet-B0 transfer learning to classify five nail conditions from digital images, with a focus on class imbalance, augmentation, and rigorous model evaluation.
Automated Image Classification for Imbalanced Medical Imaging
This project explores automated classification of five nail conditions using a convolutional neural network based on EfficientNet-B0.
Classification Under Severe Imbalance
The primary challenge is not simply image classification, but handling a highly imbalanced dataset where Acral Lentiginous Melanoma has only 21 images compared with hundreds of samples in the other classes. Standard deep learning classifiers trained on such distributions readily collapse into trivial majority-class predictors, achieving illusory high accuracy while failing entirely on the critical minority condition.
To overcome this challenge, the pipeline combines stratified dataset partitioning, targeted minority data augmentation, pretrained feature extraction via EfficientNet-B0, regularized dropout & early stopping, and multi-metric per-class evaluation.
2,205 Clinical Nail Images & Class Distribution
A comprehensive distribution audit illustrating the substantial disparity between majority dermatological classes and the extreme minority melanoma class.
Class Frequency Disparity
Key Technical Obstacles in Medical Nail Classification
Beyond standard computer vision benchmarks, clinical nail pathology presents distinct computer vision hurdles.
The dataset contains a severe imbalance between classes, with Acral Lentiginous Melanoma represented by only 21 images. Standard unweighted optimization would cause the model to ignore this minority class without incurring a significant loss penalty.
Class Imbalance
Risk of majority-class bias where a naive classifier achieves 99% overall accuracy while failing 100% of minority melanoma cases.
Visual Similarity Between Conditions
Subtle color nuances and overlapping discoloration patterns between subungual hematomas, melanomas, and severe cyanosis.
Intra-Class Variation
Significant variations in photographic angles, patient skin tones, lighting conditions, background clutter, and disease stage.
Limited Medical Imaging Data
Clinical scarcity and ethical privacy constraints restrict the volume of labeled digital dermatology datasets.
Preprocessing, Stratified Splitting & Targeted Augmentation
A robust transformation pipeline engineered to preserve label proportions and synthesize controlled variations for the minority class.

Visual comparison from the Jupyter notebook showing original sample images alongside 4 randomized augmentations per row.
Simulates varying camera angles and finger orientations during clinical mobile photography.
Provides mirror-invariance so left vs right hand digit anatomy does not bias feature extraction.
Alters brightness and contrast to simulate different hospital lighting and ambient environments.
Crops patches at scales 0.8–1.0 to enforce scale invariance and focus on localized lesions.
EfficientNet-B0 Transfer Learning Architecture
EfficientNet-B0 was selected as a compact transfer-learning backbone that provides a practical balance between model capacity and computational efficiency.
Architectural Rationale
Pretrained convolutional weights from ImageNet encode rich universal representations (edges, textures, gradients) that transfer effectively to medical pathology. By freezing the convolutional backbone (requires_grad = False) and only fine-tuning the classification head, the network avoids catastrophic forgetting and prevents overfitting on the small dataset.
Optimization & Regularization Protocol
Detailed parameters and stabilization mechanics employed during model convergence.
Optimization Hyperparameters
Imbalance & Regularization Defense
Empirical Results & Test Set Performance
Comprehensive multi-metric evaluation across 331 completely unseen test images, utilizing verified plots and classification metrics from the repository.
Detailed Per-Class Classification Report
| CLASS NAME | PRECISION | RECALL | F1-SCORE | TEST SUPPORT | PERFORMANCE NOTE |
|---|---|---|---|---|---|
Acral Lentiginous MelanomaMinority | 0.50 | 0.67 | 0.57 | 3 | Minority class with 2 of 3 test cases correctly classified |
Healthy Nail | 1.00 | 0.98 | 0.99 | 51 | Exceptional differentiation from all pathological states |
Onychogryphosis | 0.97 | 0.96 | 0.96 | 90 | Strong identification of severe nail thickening |
Blue Finger | 0.92 | 0.95 | 0.93 | 92 | Robust cyanotic color space recognition |
Pitting | 0.94 | 0.92 | 0.93 | 95 | High accuracy on punctate textural depressions |
| Overall Accuracy | 311 / 331 correct | 0.94 | 331 | 94.00% overall test accuracy | |
| Macro Average | 0.86 | 0.89 | 0.88 | 331 | Unweighted mean reflecting minority class challenge |
| Weighted Average | 0.94 | 0.94 | 0.94 | 331 | Sample-weighted score across all classes |



Why 94% Overall Accuracy Is Not the Whole Story
An analytical breakdown of model behavior across majority vs. minority conditions in imbalanced medical imaging.
The Disparity Between Overall Accuracy & Minority Recall
While headline metrics indicate a strong 94.00% test accuracy and 0.94 weighted F1, examining unweighted per-class performance reveals that the minority Acral Lentiginous Melanoma class achieved an F1-score of 0.57 (Precision: 0.50, Recall: 0.67).
In clinical settings, false negatives on melanoma represent high diagnostic risk. This experiment underscores why relying solely on accuracy in medical machine learning creates false confidence. Reporting Macro F1 (0.88), per-class confusion matrices, and precision-recall trade-offs is essential for transparent model auditing.
Training from scratch on 2,205 images caused severe feature degradation. ImageNet feature reuse provided the invariant textural descriptors necessary to distinguish nail dystrophies.
Without 10× targeted augmentation, the model predicted zero ALM cases. Synthetic perturbation expanded the decision boundary sufficiently to achieve 0.67 recall on unseen test data.
Healthy nail was effortlessly classified (0.99 F1), whereas micro-indentation conditions (Pitting) exhibited minor confusion with early Onychogryphosis.
Complete Machine Learning Lifecycle
A structured 8-stage pipeline from raw image ingestion to analytical metric interpretation.
Data Loading
Ingested 2,205 digital nail photographs across 5 clinical directory classes.
Imbalance Auditing
Identified severe 0.95% minority proportion in Acral Lentiginous Melanoma (21 images).
Stratified Splitting
Partitioned data into 70% Train (1,543), 15% Val (331), and 15% Test (331) sets.
Targeted Augmentation
Synthesized 10 variations per ALM image (rotations, flips, color jitter, crops).
EfficientNet-B0 Setup
Loaded ImageNet weights, froze convolutional feature extractor, attached custom head.
Regularized Training
Trained using Adam optimizer (lr=0.001), CrossEntropyLoss, and Early Stopping @ 67 epochs.
Test Set Evaluation
Computed per-class confusion matrix, ROC curves, macro/weighted F1 on 331 test images.
Result Interpretation
Analyzed minority recall dynamics and documented clinical trade-offs transparently.
Tools & Technologies Used
Clean, modern deep learning stack utilized throughout experimentation and model evaluation.
PyTorch & Torchvision
Model architecture definition, tensor operations, EfficientNet-B0 pretrained weights, and custom DataLoader pipelines.
Scikit-learn
Stratified train/val/test splitting, confusion matrix calculation, classification report generation, and multi-class ROC-AUC computation.
NumPy & Pandas
Dataset distribution indexing, class frequency calculations, and metric array aggregation.
PIL / Pillow
Image loading, color space verification (EnsureRGB), and dynamic image transform pipelines.
Matplotlib & Seaborn
Training loss/accuracy progression plotting, confusion matrix heatmaps, and multi-class ROC curve charting.
Transfer Learning & Augmentation
Pretrained compound scaling backbones, frozen feature extraction, random affine transformations, and early stopping regularization.
Individual Engineering Contributions
Core technical areas architected and executed in this computer vision case study.
Deep Learning Pipeline
Engineered the complete computer vision workflow in PyTorch from raw image loading, preprocessing, and normalization through batch evaluation.
Transfer Learning Backbone
Implemented EfficientNet-B0 with ImageNet pretrained weights, freezing feature layers and tuning custom Dropout (0.2) + Linear classifier layers.
Class Imbalance Handling
Engineered stratified 70/15/15 data partitioning and targeted 10× augmentation transforms to expand the extreme 21-sample minority class.
Multi-Metric Model Evaluation
Evaluated performance using per-class precision, recall, F1-scores, confusion matrices, and ROC-AUC curves on a 331-image holdout test partition.
ML Analysis & Insight
Interpreted model behavior beyond headline accuracy, demonstrating the trade-offs of severe imbalance on rare condition detection.
Academic Research & Portfolio Disclaimer
This project is an academic computer vision and deep learning case study exploring transfer learning and class imbalance in medical image classification. It is not a clinically validated diagnostic system and is not intended for clinical diagnosis, patient screening, or treatment guidance. It demonstrates machine learning classification methodology, data augmentation techniques, and empirical evaluation practices.
Inspect the Nail Disease Classification Repository
Explore the complete Jupyter notebook with PyTorch implementation, training curves, confusion matrix generation, and evaluation pipelines.