Instructions to use lederyou/bacteria-classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- timm
How to use lederyou/bacteria-classifier with timm:
import timm model = timm.create_model("hf_hub:lederyou/bacteria-classifier", pretrained=True) - Notebooks
- Google Colab
- Kaggle
Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
tags:
|
| 3 |
+
- image-classification
|
| 4 |
+
- bacteria
|
| 5 |
+
- microscopy
|
| 6 |
+
- transfer-learning
|
| 7 |
+
- efficientnet
|
| 8 |
+
library_name: timm
|
| 9 |
+
datasets:
|
| 10 |
+
- custom
|
| 11 |
+
pipeline_tag: image-classification
|
| 12 |
+
---
|
| 13 |
+
|
| 14 |
+
# Bacteria Image Classifier (EfficientNet-B0)
|
| 15 |
+
|
| 16 |
+
A fine-tuned EfficientNet-B0 model for classifying microscopy images of bacteria
|
| 17 |
+
and fungi into 20 classes (10 organisms Γ 2 imaging types: gram stain and media plate).
|
| 18 |
+
|
| 19 |
+
## Classes
|
| 20 |
+
|
| 21 |
+
The model distinguishes between the following 20 classes:
|
| 22 |
+
|
| 23 |
+
| Organism | Gram Stain | Media Plate |
|
| 24 |
+
|----------|-----------|-------------|
|
| 25 |
+
| Aspergillus niger | β | β |
|
| 26 |
+
| Bacillus subtilis | β | β |
|
| 27 |
+
| Candida albicans | β | β |
|
| 28 |
+
| Clostridium sporogenes | β | β |
|
| 29 |
+
| Enterococcus faecalis | β | β |
|
| 30 |
+
| Escherichia coli | β | β |
|
| 31 |
+
| Klebsiella pneumoniae | β | β |
|
| 32 |
+
| Pseudomonas aeruginosa | β | β |
|
| 33 |
+
| Staphylococcus aureus | β | β |
|
| 34 |
+
| Streptococcus pyogenes | β | β |
|
| 35 |
+
|
| 36 |
+
## Usage
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
import timm, torch, json
|
| 40 |
+
from torchvision import transforms
|
| 41 |
+
from PIL import Image
|
| 42 |
+
from huggingface_hub import hf_hub_download
|
| 43 |
+
|
| 44 |
+
repo_id = "lederyou/bacteria-classifier"
|
| 45 |
+
model_path = hf_hub_download(repo_id, "model.pth")
|
| 46 |
+
class_names = json.load(open(hf_hub_download(repo_id, "class_names.json")))
|
| 47 |
+
|
| 48 |
+
model = timm.create_model("efficientnet_b0", pretrained=False, num_classes=20)
|
| 49 |
+
model.load_state_dict(torch.load(model_path, map_location="cpu"))
|
| 50 |
+
model.eval()
|
| 51 |
+
|
| 52 |
+
transform = transforms.Compose([
|
| 53 |
+
transforms.Resize((224, 224)),
|
| 54 |
+
transforms.ToTensor(),
|
| 55 |
+
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
|
| 56 |
+
])
|
| 57 |
+
|
| 58 |
+
img = transform(Image.open("your_image.png").convert("RGB")).unsqueeze(0)
|
| 59 |
+
with torch.no_grad():
|
| 60 |
+
pred = model(img).argmax(1).item()
|
| 61 |
+
print(class_names[pred])
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
## Training
|
| 65 |
+
|
| 66 |
+
- **Base model**: EfficientNet-B0 (pretrained on ImageNet)
|
| 67 |
+
- **Method**: Two-phase transfer learning (frozen backbone β full fine-tuning)
|
| 68 |
+
- **Dataset**: 629 images, 20 classes, 70/15/15 train/val/test split
|