Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- vi
|
| 4 |
+
- en
|
| 5 |
+
license: mit
|
| 6 |
+
tags:
|
| 7 |
+
- agriculture
|
| 8 |
+
- tomato
|
| 9 |
+
- plant-disease
|
| 10 |
+
- computer-vision
|
| 11 |
+
- resnet18
|
| 12 |
+
- grad-cam
|
| 13 |
+
- leaf-ai
|
| 14 |
+
datasets:
|
| 15 |
+
- wellCh4n/tomato-leaf-disease-image
|
| 16 |
+
metrics:
|
| 17 |
+
- accuracy
|
| 18 |
+
pipeline_tag: image-classification
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
# 🍃 LEAF_AI — Tomato Leaf Disease ResNet-18 Model
|
| 22 |
+
|
| 23 |
+
Mô hình Deep Learning thị giác máy tính nhận diện **10 lớp bệnh & trạng thái lá cây cà chua** chuẩn hóa quốc tế (theo phân loại PlantVillage & Tổ chức Lương thực và Nông nghiệp Liên Hợp Quốc - FAO). Tích hợp cơ chế giải thích quyết định thị giác **Grad-CAM (Gradient-weighted Class Activation Mapping)**.
|
| 24 |
+
|
| 25 |
+
## 🎯 10 Lớp bệnh & phân loại
|
| 26 |
+
| ID | Tên tiếng Anh | Tên tiếng Việt | Tác nhân gây bệnh |
|
| 27 |
+
|---|---|---|---|
|
| 28 |
+
| 0 | `Healthy` | Lá khỏe mạnh | Không có mầm bệnh |
|
| 29 |
+
| 1 | `Leaf_mold` | Nấm mốc lá | *Passalora fulva* |
|
| 30 |
+
| 2 | `Target_spot` | Đốm mắt cua | *Corynespora cassiicola* |
|
| 31 |
+
| 3 | `Late_blight` | Sương mai | *Phytophthora infestans* |
|
| 32 |
+
| 4 | `Early_blight` | Úa sớm (Đốm vòng) | *Alternaria solani* |
|
| 33 |
+
| 5 | `Bacterial_spot` | Đốm vi khuẩn | *Xanthomonas campestris* |
|
| 34 |
+
| 6 | `Septoria_leaf_spot` | Đốm lá Septoria | *Septoria lycopersici* |
|
| 35 |
+
| 7 | `Tomato_mosaic_virus` | Khảm lá virus (ToMV) | Tomato mosaic tobamovirus |
|
| 36 |
+
| 8 | `Tomato_yellow_leaf_curl_virus` | Xoăn vàng lá virus (TYLCV) | Begomovirus (Vector: Bọ phấn trắng) |
|
| 37 |
+
| 9 | `Spider_mites` | Nhện đỏ hai chấm | *Tetranychus urticae* |
|
| 38 |
+
|
| 39 |
+
## 📊 Kết quả Huấn luyện (Training Metrics)
|
| 40 |
+
- **Kiến trúc Backbone**: ResNet-18 (Pretrained ImageNet)
|
| 41 |
+
- **Tập dữ liệu huấn luyện**: 14,218 ảnh thực tế (PlantVillage Tomato Dataset)
|
| 42 |
+
- **Tập kiểm thử (Validation)**: 3,569 ảnh
|
| 43 |
+
- **Độ chính xác kiểm thử (Validation Accuracy)**: **>97.8%**
|
| 44 |
+
- **Độ trễ suy luận (Inference Latency)**: ~15ms trên CPU / ~2ms trên GPU CUDA
|
| 45 |
+
|
| 46 |
+
## 💻 Cách sử dụng trong PyTorch
|
| 47 |
+
```python
|
| 48 |
+
import torch
|
| 49 |
+
import torchvision.models as models
|
| 50 |
+
import torchvision.transforms as transforms
|
| 51 |
+
from PIL import Image
|
| 52 |
+
|
| 53 |
+
# 1. Khởi tạo mô hình
|
| 54 |
+
classes = [
|
| 55 |
+
"Healthy", "Leaf_mold", "Target_spot", "Late_blight", "Early_blight",
|
| 56 |
+
"Bacterial_spot", "Septoria_leaf_spot", "Tomato_mosaic_virus",
|
| 57 |
+
"Tomato_yellow_leaf_curl_virus", "Spider_mites"
|
| 58 |
+
]
|
| 59 |
+
|
| 60 |
+
checkpoint = torch.load("tomato_model.pt", map_location="cpu")
|
| 61 |
+
model = models.resnet18()
|
| 62 |
+
model.fc = torch.nn.Sequential(
|
| 63 |
+
torch.nn.Dropout(p=0.3),
|
| 64 |
+
torch.nn.Linear(model.fc.in_features, len(classes))
|
| 65 |
+
)
|
| 66 |
+
model.load_state_dict(checkpoint["model_state_dict"])
|
| 67 |
+
model.eval()
|
| 68 |
+
|
| 69 |
+
# 2. Tiền xử lý & Dự đoán
|
| 70 |
+
transform = transforms.Compose([
|
| 71 |
+
transforms.Resize((224, 224)),
|
| 72 |
+
transforms.ToTensor(),
|
| 73 |
+
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
|
| 74 |
+
])
|
| 75 |
+
|
| 76 |
+
img = Image.open("tomato_leaf.jpg").convert("RGB")
|
| 77 |
+
tensor = transform(img).unsqueeze(0)
|
| 78 |
+
|
| 79 |
+
with torch.no_grad():
|
| 80 |
+
probs = torch.softmax(model(tensor), dim=1)[0]
|
| 81 |
+
top_p, top_i = torch.topk(probs, 3)
|
| 82 |
+
for p, idx in zip(top_p, top_i):
|
| 83 |
+
print(f"{classes[idx]}: {p.item()*100:.2f}%")
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
## 🛡️ Bản quyền & Nguồn
|
| 87 |
+
- Dự án: **LEAF_AI (Hệ sinh thái AI nông nghiệp thông minh)**
|
| 88 |
+
- Dataset: `wellCh4n/tomato-leaf-disease-image` (PlantVillage)
|