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 |
+
- pytorch
|
| 9 |
+
- dibas
|
| 10 |
+
datasets:
|
| 11 |
+
- custom
|
| 12 |
+
metrics:
|
| 13 |
+
- accuracy
|
| 14 |
+
- f1
|
| 15 |
+
library_name: timm
|
| 16 |
+
pipeline_tag: image-classification
|
| 17 |
+
---
|
| 18 |
+
|
| 19 |
+
# EfficientNet-B0 for Bacterial Colony Classification
|
| 20 |
+
|
| 21 |
+
This model is a fine-tuned version of **EfficientNet-B0** on the [DIBaS (Digital Image of Bacterial Species)](http://misztal.edu.pl/software/databases/dibas/) dataset for classifying bacterial colony images into 33 species.
|
| 22 |
+
|
| 23 |
+
## Model Description
|
| 24 |
+
|
| 25 |
+
- **Model Architecture:** EfficientNet-B0 (pretrained on ImageNet)
|
| 26 |
+
- **Task:** Multi-class image classification (33 bacterial species)
|
| 27 |
+
- **Dataset:** DIBaS - 660+ microscopy images of bacterial colonies
|
| 28 |
+
- **Framework:** PyTorch + timm
|
| 29 |
+
|
| 30 |
+
## Performance
|
| 31 |
+
|
| 32 |
+
| Metric | Value |
|
| 33 |
+
|--------|-------|
|
| 34 |
+
| **Validation Accuracy** | 91.67% |
|
| 35 |
+
| **Macro F1-Score** | 0.917 |
|
| 36 |
+
| **Parameters** | 4.05M |
|
| 37 |
+
| **Model Size** | 15.7 MB |
|
| 38 |
+
| **GPU Latency** | 5.81 ms (RTX 4070 SUPER) |
|
| 39 |
+
| **CPU Latency** | 25.76 ms |
|
| 40 |
+
|
| 41 |
+
### Comparison with Other Models
|
| 42 |
+
|
| 43 |
+
| Model | Params (M) | Val Accuracy |
|
| 44 |
+
|-------|------------|--------------|
|
| 45 |
+
| MobileNetV3-Large | 4.24 | **95.45%** |
|
| 46 |
+
| ResNet50 | 23.58 | 93.94% |
|
| 47 |
+
| **EfficientNet-B0** | 4.05 | 91.67% |
|
| 48 |
+
|
| 49 |
+
## Why Choose EfficientNet-B0?
|
| 50 |
+
|
| 51 |
+
- ✅ **Smallest parameter count** (4.05M) among top performers
|
| 52 |
+
- ✅ **Excellent accuracy-to-size ratio**
|
| 53 |
+
- ✅ **Good balance** between speed and accuracy
|
| 54 |
+
- ✅ **Mobile-friendly** for edge deployment
|
| 55 |
+
|
| 56 |
+
## Training Details
|
| 57 |
+
|
| 58 |
+
- **Optimizer:** AdamW (lr=1e-3, weight_decay=1e-4)
|
| 59 |
+
- **Epochs:** 10 (early convergence)
|
| 60 |
+
- **Batch Size:** 32
|
| 61 |
+
- **Image Size:** 224×224
|
| 62 |
+
- **Augmentation:** RandomResizedCrop, HorizontalFlip
|
| 63 |
+
- **Hardware:** NVIDIA RTX 4070 SUPER
|
| 64 |
+
- **Mixed Precision:** Enabled (AMP)
|
| 65 |
+
- **Train/Val/Test Split:** 70/20/10 (stratified, seed=42)
|
| 66 |
+
|
| 67 |
+
## How to Use
|
| 68 |
+
|
| 69 |
+
```python
|
| 70 |
+
import timm
|
| 71 |
+
import torch
|
| 72 |
+
from PIL import Image
|
| 73 |
+
from torchvision import transforms
|
| 74 |
+
|
| 75 |
+
# Load model
|
| 76 |
+
model = timm.create_model('efficientnet_b0', pretrained=False, num_classes=33)
|
| 77 |
+
state_dict = torch.load('pytorch_model.bin', map_location='cpu')
|
| 78 |
+
model.load_state_dict(state_dict)
|
| 79 |
+
model.eval()
|
| 80 |
+
|
| 81 |
+
# Preprocessing
|
| 82 |
+
transform = transforms.Compose([
|
| 83 |
+
transforms.Resize(256),
|
| 84 |
+
transforms.CenterCrop(224),
|
| 85 |
+
transforms.ToTensor(),
|
| 86 |
+
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
|
| 87 |
+
])
|
| 88 |
+
|
| 89 |
+
# Inference
|
| 90 |
+
image = Image.open('bacteria_image.jpg').convert('RGB')
|
| 91 |
+
input_tensor = transform(image).unsqueeze(0)
|
| 92 |
+
|
| 93 |
+
with torch.no_grad():
|
| 94 |
+
outputs = model(input_tensor)
|
| 95 |
+
predicted_class = outputs.argmax(dim=1).item()
|
| 96 |
+
|
| 97 |
+
print(f"Predicted class: {CLASS_NAMES[predicted_class]}")
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
### Class Labels
|
| 101 |
+
|
| 102 |
+
```python
|
| 103 |
+
CLASS_NAMES = [
|
| 104 |
+
"Acinetobacter_baumannii", "Actinomyces_israelii", "Bacteroides_fragilis",
|
| 105 |
+
"Bifidobacterium_spp", "Candida_albicans", "Clostridium_perfringens",
|
| 106 |
+
"Enterococcus_faecalis", "Enterococcus_faecium", "Escherichia_coli",
|
| 107 |
+
"Fusobacterium", "Lactobacillus_casei", "Lactobacillus_crispatus",
|
| 108 |
+
"Lactobacillus_delbrueckii", "Lactobacillus_gasseri", "Lactobacillus_jensenii",
|
| 109 |
+
"Lactobacillus_johnsonii", "Lactobacillus_paracasei", "Lactobacillus_plantarum",
|
| 110 |
+
"Lactobacillus_reuteri", "Lactobacillus_rhamnosus", "Lactobacillus_salivarius",
|
| 111 |
+
"Listeria_monocytogenes", "Micrococcus_spp", "Neisseria_gonorrhoeae",
|
| 112 |
+
"Porphyromonas_gingivalis", "Propionibacterium_acnes", "Proteus",
|
| 113 |
+
"Pseudomonas_aeruginosa", "Staphylococcus_aureus", "Staphylococcus_epidermidis",
|
| 114 |
+
"Staphylococcus_saprophyticus", "Streptococcus_agalactiae", "Veillonella"
|
| 115 |
+
]
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
## Limitations
|
| 119 |
+
|
| 120 |
+
- Trained on single laboratory/microscope setup (DIBaS dataset)
|
| 121 |
+
- May not generalize to different imaging conditions
|
| 122 |
+
- Not validated for clinical diagnostic use
|
| 123 |
+
|
| 124 |
+
## Related Models
|
| 125 |
+
|
| 126 |
+
- [MobileNetV3-Large](https://huggingface.co/ihoflaz/dibas-mobilenet-v3-large) - Best accuracy (95.45%)
|
| 127 |
+
- [ResNet50](https://huggingface.co/ihoflaz/dibas-resnet50) - Classic architecture (93.94%)
|
| 128 |
+
|
| 129 |
+
## Citation
|
| 130 |
+
|
| 131 |
+
```bibtex
|
| 132 |
+
@inproceedings{hoflaz2025bacterial,
|
| 133 |
+
title={Lightweight CNNs Outperform Vision Transformers for Bacterial Colony Classification},
|
| 134 |
+
author={Hoflaz, Ibrahim},
|
| 135 |
+
booktitle={IEEE Conference},
|
| 136 |
+
year={2025}
|
| 137 |
+
}
|
| 138 |
+
```
|
| 139 |
+
|
| 140 |
+
## Resources
|
| 141 |
+
|
| 142 |
+
- **GitHub:** [ihoflaz/bacterial-colony-classification](https://github.com/ihoflaz/bacterial-colony-classification)
|
| 143 |
+
- **DIBaS Dataset:** [http://misztal.edu.pl/software/databases/dibas/](http://misztal.edu.pl/software/databases/dibas/)
|