Add model card for agromind-plant-disease-mobilenet
Browse files
README.md
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
tags:
|
| 4 |
+
- image-classification
|
| 5 |
+
- plant-disease
|
| 6 |
+
- agriculture
|
| 7 |
+
- mobilenet
|
| 8 |
+
- pytorch
|
| 9 |
+
library_name: pytorch
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# AgroMind Plant Disease Classifier (MobileNetV2)
|
| 13 |
+
|
| 14 |
+
## Model Description
|
| 15 |
+
MobileNetV2 image classifier trained on the New Plant Diseases Dataset to detect 38 plant disease classes. Serves as a lightweight fallback for the NFNet-F1 model.
|
| 16 |
+
|
| 17 |
+
## Framework
|
| 18 |
+
- **Architecture**: MobileNetV2 (torchvision)
|
| 19 |
+
- **Format**: PyTorch checkpoint (.pth)
|
| 20 |
+
- **Input size**: 224×224 RGB (resize to 256, center crop to 224)
|
| 21 |
+
- **Normalization**: ImageNet (mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
|
| 22 |
+
|
| 23 |
+
## Usage
|
| 24 |
+
```python
|
| 25 |
+
from huggingface_hub import hf_hub_download
|
| 26 |
+
import torch
|
| 27 |
+
from torchvision import models, transforms
|
| 28 |
+
from PIL import Image
|
| 29 |
+
|
| 30 |
+
repo_id = "Arko007/agromind-plant-disease-mobilenet"
|
| 31 |
+
ckpt = hf_hub_download(repo_id, "newplant_model_final.pth")
|
| 32 |
+
labels_path = hf_hub_download(repo_id, "labels.txt")
|
| 33 |
+
|
| 34 |
+
with open(labels_path) as f:
|
| 35 |
+
labels = [l.strip() for l in f if l.strip()]
|
| 36 |
+
|
| 37 |
+
model = models.mobilenet_v2(pretrained=False)
|
| 38 |
+
model.classifier[1] = torch.nn.Linear(model.classifier[1].in_features, len(labels))
|
| 39 |
+
state = torch.load(ckpt, map_location="cpu")
|
| 40 |
+
model.load_state_dict(state)
|
| 41 |
+
model.eval()
|
| 42 |
+
|
| 43 |
+
transform = transforms.Compose([
|
| 44 |
+
transforms.Resize(256),
|
| 45 |
+
transforms.CenterCrop(224),
|
| 46 |
+
transforms.ToTensor(),
|
| 47 |
+
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
|
| 48 |
+
])
|
| 49 |
+
|
| 50 |
+
img = Image.open("leaf.jpg").convert("RGB")
|
| 51 |
+
with torch.no_grad():
|
| 52 |
+
logits = model(transform(img).unsqueeze(0))
|
| 53 |
+
print(labels[logits.argmax(dim=1).item()])
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
## Output
|
| 57 |
+
Returns logits for 38 plant disease classes. See `labels.txt` for class names.
|