AgriAI - Crop Disease Detection Models

Two MobileNetV2-based models used in the AgriAI project:

  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

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]

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Space using AAYUSHSAVALIYA/agri-ai-model 1