SMIDS Three-Class Sperm Morphology Classifiers (ResNet50 & EfficientNet-B0)
Research checkpoints accompanying the paper
Calibration and Cross-Validation of ResNet50 and EfficientNet-B0 for Three-Class Sperm Morphology Classification Saurabh Uttam Mane, Neha Raut. Dept. of Artificial Intelligence and Data Science, Vidyavardhini's College of Engineering and Technology, Vasai Road, Mumbai, India.
The models classify stained sperm microscopy crops from the SMIDS dataset into abnormal sperm, non-sperm debris, and normal sperm. Non-sperm debris is kept as its own class, so the classifier does not have to place debris into a sperm class.
TL;DR
- EfficientNet-B0 beats ResNet50 in five-fold cross-validation (85.08 Β± 1.90 % vs 79.19 Β± 3.20 %) and varies less across folds, with about 5Γ fewer parameters.
- Dirichlet calibration cut expected calibration error to β 0.03, while temperature scaling made it worse.
- The released fold checkpoints reach 85.2 % (EfficientNet-B0) and 78.8 % (ResNet50) on a 453-image held-out test split that neither model saw during training.
π Try it in the browser: smids-sperm-morphology-demo
β οΈ Research use only. These models are not medical devices and have not been clinically validated. Do not use them for diagnosis or treatment decisions.
Released checkpoints
| Folder | Backbone | CV fold | Params (with head) | Size | Fold-validation acc | Held-out test acc | Test macro F1 |
|---|---|---|---|---|---|---|---|
efficientnet-b0-fold5/ |
EfficientNet-B0 (torchvision) | 5 | 4.67 M | ~19 MB | 88.02 % | 85.21 % | 0.853 |
resnet50-fold3/ |
ResNet50 (torchvision) | 3 | 24.56 M | ~98 MB | 83.10 % | 78.81 % | 0.785 |
The checkpoints come from the stratified five-fold cross-validation experiment (Section III-D, Axis 5 of the paper). Each one is that architecture's best fold, so the fold-validation accuracy is an optimistic number. The held-out test columns come from these exact weights evaluated on the 453-image test split. That split was never part of the CV pool (train + validation, 2,547 images), so it is unseen by both models.
These are not the main-training (focal-loss, augmented) checkpoints behind the paper's held-out summary in Table III (ResNet50 87.64 %). Those numbers come from a different training protocol.
Labels
| Index | Label | SMIDS folder |
|---|---|---|
| 0 | abnormal |
Abnormal_Sperm |
| 1 | non_sperm |
Non-Sperm |
| 2 | normal |
Normal_Sperm |
The order is alphabetical, from sorted() over the class folders in the training data loader. It was checked by running the released weights on the test split (confusion matrices below). Note that the per-class F1 column names in the original CV script's output (val_f1_normal, val_f1_abnormal, val_f1_nonsperm) do not match this order. They actually correspond to abnormal, non-sperm and normal respectively.
Usage
pip install torch torchvision safetensors huggingface_hub pillow numpy
from modeling import load_from_hub # modeling.py from this repo
from inference import predict
model, config = load_from_hub("efficientnet_b0", repo_id="saurya-23/smids-sperm-morphology")
labels = [config["id2label"][str(i)] for i in range(3)]
print(predict(model, labels, ["sample.bmp"]))
Command line:
python inference.py sample1.bmp sample2.bmp --model efficientnet_b0
# sample1.bmp normal 0.912 ok
# sample2.bmp abnormal 0.641 REVIEW
ONNX (no PyTorch needed)
Each model folder also contains model.onnx (opset 17, dynamic batch). Input image is [N, 3, 224, 224] float32 and output logits is [N, 3]. On a sample of the test split, its outputs match PyTorch to within 1.5e-5, with identical predictions.
import numpy as np, onnxruntime as ort
from huggingface_hub import hf_hub_download
sess = ort.InferenceSession(hf_hub_download("saurya-23/smids-sperm-morphology", "efficientnet-b0-fold5/model.onnx"))
logits = sess.run(None, {"image": x})[0] # x: preprocessed float32 array, see below
To load without the helper, build torchvision.models.efficientnet_b0() / resnet50(), replace classifier / fc with the head below, wrap it as self.backbone, and call load_state_dict(safetensors.torch.load_file("model.safetensors")).
Preprocessing
- RGB image, resized to 224 Γ 224 (bilinear, no crop, aspect ratio not preserved)
- Scale to [0, 1], then normalise with ImageNet mean
(0.485, 0.456, 0.406)and std(0.229, 0.224, 0.225) - Input tensor
[N, 3, 224, 224]; output: 3 logits (apply softmax for probabilities)
Training used OpenCV/Albumentations resizing. The PIL resizing in inference.py gives the same test accuracy for ResNet50 and +0.9 pp for EfficientNet-B0 (see below).
Architecture
Both models use an ImageNet-pretrained torchvision backbone (ResNet50 IMAGENET1K_V2, EfficientNet-B0 IMAGENET1K_V1). The backbone's pooling is kept, and the original classifier is replaced by:
Dropout(0.5) β Linear(in, 512) β ReLU β BatchNorm1d(512) β Dropout(0.25) β Linear(512, 3)
Training (cross-validation protocol)
- Data: SMIDS, 3,000 images (1,021 normal / 1,005 abnormal / 974 non-sperm). Stratified 70/15/15 split into 2,098 train / 449 validation / 453 test. CV runs on train + validation combined (2,547 images) with
StratifiedKFold(n_splits=5, shuffle=True, random_state=42). - Loss: cross-entropy (not the focal loss of the main training run)
- Augmentation: none. Resize and normalise only.
- Optimiser: Adam with weight decay
- Checkpoint selection: the epoch with the highest fold-validation accuracy
Evaluation
Five-fold cross-validation (from the paper, Table VII)
| Fold | EffNet-B0 Acc | EffNet-B0 F1 | EffNet-B0 AUC | ResNet50 Acc | ResNet50 F1 | ResNet50 AUC |
|---|---|---|---|---|---|---|
| 1 | 85.49 | 0.856 | 0.9536 | 81.37 | 0.817 | 0.9414 |
| 2 | 84.12 | 0.840 | 0.9492 | 77.84 | 0.772 | 0.9340 |
| 3 | 82.91 | 0.831 | 0.9573 | 83.10 | 0.833 | 0.9533 |
| 4 | 84.87 | 0.847 | 0.9624 | 74.85 | 0.747 | 0.9145 |
| 5 | 88.02 | 0.881 | 0.9653 | 78.78 | 0.788 | 0.9420 |
| Mean Β± SD | 85.08 Β± 1.90 | 0.851 Β± 0.019 | 0.9576 Β± 0.0065 | 79.19 Β± 3.20 | 0.791 Β± 0.035 | 0.9370 Β± 0.0144 |
Bold fold rows are the released checkpoints. An exploratory paired two-tailed t-test on fold accuracies gives t(4) = 3.18, p = 0.0335. The folds share training data, so this is not independent evidence of superiority.
Released weights on the held-out test split (453 images)
OpenCV resize, matching training preprocessing:
| Model | Accuracy | Macro F1 | F1 abnormal | F1 non-sperm | F1 normal |
|---|---|---|---|---|---|
| EfficientNet-B0 (fold 5) | 85.21 % | 0.853 | 0.807 | 0.905 | 0.848 |
| ResNet50 (fold 3) | 78.81 % | 0.785 | 0.727 | 0.832 | 0.797 |
With PIL resize (inference.py): EfficientNet-B0 86.09 % / 0.862, ResNet50 78.81 % / 0.785.
Confusion matrices (rows = true, columns = predicted: abnormal, non-sperm, normal):
EfficientNet-B0 fold 5 ResNet50 fold 3
abnormal [121, 5, 26] abnormal [101, 27, 24]
non_sperm [ 13, 128, 6] non_sperm [ 7, 134, 6]
normal [ 14, 3, 137] normal [ 18, 14, 122]
Calibration (from the paper, Table V)
The paper reports ECE (10 bins) before and after calibration: ResNet50 0.120 β 0.178 (temperature, T = 1.417) / 0.036 (Dirichlet), and EfficientNet-B0 0.100 β 0.152 (temperature, T = 1.426) / 0.031 (Dirichlet). The calibrators are not included in this repository, and those numbers come from the main-training checkpoints, not from these CV-fold weights. The probabilities from these models are uncalibrated softmax outputs.
Limitations
- Trained and evaluated only on SMIDS. Performance with other microscopes, staining or sample-preparation procedures, and clinical settings is unknown.
- Inputs are expected to be single-cell crops like SMIDS images. Multi-cell or cluttered frames were not systematically evaluated, and an upstream detector was not tested.
- The 0.80 confidence referral threshold in
inference.pyis a proposed, unvalidated policy. Its referral rate and accepted-prediction accuracy have not been measured. - The models assess image morphology only. They do not measure motility, concentration or fertility outcomes.
- Grad-CAM and TTA analyses in the paper are exploratory.
Citation
The paper is not yet published. Until it is, please cite:
@misc{mane2026smids,
title = {Calibration and Cross-Validation of ResNet50 and EfficientNet-B0 for Three-Class Sperm Morphology Classification},
author = {Mane, Saurabh Uttam and Raut, Neha},
year = {2026},
note = {Preprint. Model weights: https://huggingface.co/saurya-23/smids-sperm-morphology}
}
Please also cite the dataset:
@misc{ilhan2022smids,
title = {Sperm Morphology Image Data Set (SMIDS)},
author = {Ilhan, Hamza Osman},
year = {2022},
publisher = {Mendeley Data},
version = {1},
doi = {10.17632/6xvdhc9fyb.1}
}
License
The model weights and code are released under CC BY 4.0. Anyone may use, share and adapt them, including commercially, as long as they credit the authors. The backbones were initialised from torchvision ImageNet weights (BSD-3-Clause), and SMIDS is distributed under CC BY 4.0 on Mendeley Data.
Space using saurya-23/smids-sperm-morphology 1
Evaluation results
- Test accuracy on SMIDS (453-image held-out test split)self-reported85.210
- Test macro F1 on SMIDS (453-image held-out test split)self-reported0.853
- Test accuracy on SMIDS (453-image held-out test split)self-reported78.810
- Test macro F1 on SMIDS (453-image held-out test split)self-reported0.785