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