Two MobileNetV2-based models used in the AgriAI project:
Fuente del modelo
Descripción de la fuente
Two MobileNetV2-based models used in the AgriAI project:
Fuentes
1 fuenteVerificado 27 ago
Artefactos del modelo
2 artefactosExtractos de fuentes
2 extractosweights=None, trained from scratch/fine-tuned)nn.Linear(num_features, len(class_names))class_names and model_state_dict keysfrom huggingface_hub import hf_hub_download
import torch, torch.nn as nn
from torchvision import models, transforms
from PIL import Image
model_path = hf_hub_download("AAYUSHSAVALIYA/agri-ai-model", "model.pth")
checkpoint = torch.load(model_path, map_location="cpu")
class_names = checkpoint["class_names"]
model = models.mobilenet_v2(weights=None)
model.classifier[1] = nn.Linear(model.classifier[1].in_features, len(class_names))
model.load_state_dict(checkpoint["model_state_dict"])
model.eval()
transform = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])
img = Image.open("leaf.jpg").convert("RGB")
with torch.no_grad():
output = model(transform(img).unsqueeze(0))
pred = output.argmax(dim=1).item()
print(class_names[pred])
[list your crop/disease class names here — pull from class_names in the checkpoint]
--- license: mit tags: - image-classification - agriculture - pytorch - mobilenet-v2 - plant-disease --- # AgriAI - Crop Disease Detection Models Two MobileNetV2-based models used in the [AgriAI project](https://github.com/Parth070711/AgriAI): 1. **model.pth** — classifies crop leaf diseases (tomato, potato, pepper, rice, bitter gourd) 2. **leaf_detector.pth** — checks whether an uploaded image is actually a valid leaf ## Architecture - Backbone: MobileNetV2 (torchvision, `weights=None`, trained from scratch/fine-tuned) - Final layer: `nn.Linear(num_features, len(class_names))` - Checkpoint format: dict with `class_names` and `model_state_dict` keys ## Usage ```python from huggingface_hub import hf_hub_download import torch, torch.nn as nn from torchvision import models, transforms from PIL import Image model_path = hf_hub_download("AAYUSHSAVALIYA/agri-ai-model", "model.pth") checkpoint = torch.load(model_path, map_location="cpu") class_names = checkpoint["class_names"] model = models.mobilenet_v2(weights=None) model.classifier[1] = nn.Linear(model.classifier[1].in_features, len(class_names)) model.load_state_dict(checkpoint["model_state_dict"]) model.eval() transform = transforms.Compose([ transforms.Resize((224, 224)), transforms.ToTensor(), transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]) ]) img = Image.open("leaf.jpg").convert("RGB") with torch.no_grad(): output = model(transform(img).unsqueeze(0)) pred = output.argmax(dim=1).item() print(class_names[pred]) ``` ## Classes [list your crop/disease class names here — pull from `class_names` in the checkpoint]
Source context: 0 downloads · 1 likes · Pipeline image-classification · Repo AAYUSHSAVALIYA/agri-ai-model