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
File size: 1,949 Bytes
3dab422 | 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 | ---
tags:
- image-classification
- bacteria
- microscopy
- transfer-learning
- efficientnet
library_name: timm
datasets:
- custom
pipeline_tag: image-classification
---
# Bacteria Image Classifier (EfficientNet-B0)
A fine-tuned EfficientNet-B0 model for classifying microscopy images of bacteria
and fungi into 20 classes (10 organisms Γ 2 imaging types: gram stain and media plate).
## Classes
The model distinguishes between the following 20 classes:
| Organism | Gram Stain | Media Plate |
|----------|-----------|-------------|
| Aspergillus niger | β | β |
| Bacillus subtilis | β | β |
| Candida albicans | β | β |
| Clostridium sporogenes | β | β |
| Enterococcus faecalis | β | β |
| Escherichia coli | β | β |
| Klebsiella pneumoniae | β | β |
| Pseudomonas aeruginosa | β | β |
| Staphylococcus aureus | β | β |
| Streptococcus pyogenes | β | β |
## Usage
```python
import timm, torch, json
from torchvision import transforms
from PIL import Image
from huggingface_hub import hf_hub_download
repo_id = "lederyou/bacteria-classifier"
model_path = hf_hub_download(repo_id, "model.pth")
class_names = json.load(open(hf_hub_download(repo_id, "class_names.json")))
model = timm.create_model("efficientnet_b0", pretrained=False, num_classes=20)
model.load_state_dict(torch.load(model_path, map_location="cpu"))
model.eval()
transform = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
])
img = transform(Image.open("your_image.png").convert("RGB")).unsqueeze(0)
with torch.no_grad():
pred = model(img).argmax(1).item()
print(class_names[pred])
```
## Training
- **Base model**: EfficientNet-B0 (pretrained on ImageNet)
- **Method**: Two-phase transfer learning (frozen backbone β full fine-tuning)
- **Dataset**: 629 images, 20 classes, 70/15/15 train/val/test split
|