--- license: mit language: - en tags: - malaria - medical-imaging - blood-smear - microscopy - image-classification - pytorch - mobilenetv2 - transfer-learning datasets: - NIH-Malaria-Cell-Images metrics: - accuracy - f1 - precision - recall pipeline_tag: image-classification library_name: pytorch --- # MobileNetV2 (Fine-Tuned) — Malaria Parasite Detection **Recommended production model.** Fine-tuned MobileNetV2 for malaria parasite detection from thin blood smear microscopy images. Achieves **97.97% test accuracy** — the highest in our model family. Part of [LocalMedScan](https://github.com/Svetozar-Technologies/LocalMedScan). ## Model Details | Property | Value | |:---------|:------| | **Architecture** | MobileNetV2 (ImageNet pretrained, fine-tuned) | | **Parameters** | ~3.4M | | **Model Size** | 14 MB | | **Input** | RGB 224x224 blood smear cell images | | **Output** | Binary classification: Parasitized vs Uninfected | | **Training** | 3-phase progressive unfreezing from ImageNet weights | | **Framework** | PyTorch | | **License** | MIT | ## Performance ### Test Results (NIH Malaria Dataset, 2,757 test images) | Metric | Without TTA | With 5-View TTA | |:-------|:-----------:|:----------------:| | **Accuracy** | 97.68% | **97.97%** | | **Sensitivity** | 97.12% | 97.41% | | **Specificity** | 98.22% | 98.51% | | **Precision** | 98.19% | 98.49% | | **F1 Score** | 97.65% | 97.95% | ### Comparison with PlasmoSENet | Model | Params | Size | Accuracy (TTA) | F1 | Training | |:------|:------:|:----:|:--------------:|:--:|:---------| | **MobileNetV2** (this model) | 3.4M | 14 MB | **97.97%** | **97.95%** | Fine-tuned from ImageNet | | [PlasmoSENet](https://huggingface.co/Svetozar1993/LocalMedScan-malaria-plasmosenet) | 10.6M | 41 MB | 96.55% | 96.47% | Trained from scratch | MobileNetV2 outperforms PlasmoSENet by 1.42 percentage points while being 3x smaller and 3x faster. Transfer learning from ImageNet provides a decisive advantage on this dataset size (27K images). **Use MobileNetV2 for deployment. Use PlasmoSENet for research** into domain-specific architectures or when ImageNet-free training is required. ## Key Achievements 1. **97.97% test accuracy** with 5-view TTA — exceeds most published results on this benchmark 2. **3-phase progressive unfreezing** prevents catastrophic forgetting while maximizing adaptation 3. **TransformSubset bug fix** — corrected a common PyTorch `random_split` bug where train/val/test subsets inadvertently share transforms, causing training to run without augmentation 4. **5-view TTA** exploiting blood cell rotational invariance (+0.29% accuracy) 5. **Lightweight** — 14 MB model runs on any device including mobile ## Training Details ### 3-Phase Progressive Unfreezing - **Phase 1**: Classifier head only (frozen backbone) - **Phase 2**: Last inverted residual blocks unfrozen, reduced LR - **Phase 3**: Full end-to-end fine-tuning, further reduced LR ### Augmentation Strong augmentation pipeline with RandomResizedCrop, RandomRotation(90), ColorJitter, GaussianBlur, and RandomErasing. The `TransformSubset` wrapper ensures training and validation use independent transforms. ## Dataset **NIH Malaria Cell Images Dataset** (Rajaraman et al., 2018) - 27,558 annotated cell images from Giemsa-stained thin blood smears - 13,779 Parasitized + 13,779 Uninfected (balanced) - Split: 80% train / 10% val / 10% test (seed=42) ## Usage ```python import torch import torchvision.models as models # Load model model = models.mobilenet_v2(weights=None) model.classifier[1] = torch.nn.Linear(model.last_channel, 2) state_dict = torch.load("model.pth", map_location="cpu", weights_only=True) model.load_state_dict(state_dict) model.eval() # Inference from torchvision import transforms from PIL import Image transform = transforms.Compose([ transforms.Resize((224, 224)), transforms.ToTensor(), transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), ]) img = Image.open("blood_smear_cell.png").convert("RGB") tensor = transform(img).unsqueeze(0) with torch.inference_mode(): probs = torch.softmax(model(tensor), dim=1) # probs[0][0] = Parasitized, probs[0][1] = Uninfected ``` ## Links - **GitHub**: [Svetozar-Technologies/LocalMedScan](https://github.com/Svetozar-Technologies/LocalMedScan) - **PlasmoSENet Model**: [Svetozar1993/LocalMedScan-malaria-plasmosenet](https://huggingface.co/Svetozar1993/LocalMedScan-malaria-plasmosenet) - **Dataset**: [NIH Malaria Cell Images](https://lhncbc.nlm.nih.gov/LHC-downloads/downloads.html#malaria-datasets)