Downloads · 30 days
11
17% of all-time downloads
albertosei/agricom-maize-new-resnet18
agricom-maize-new-resnet18 is a machine learning model from albertosei. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as apache-2.0.
Downloads · 30 days
11
17% of all-time downloads
All-time downloads
66
Public
Parameters
11.2M
89.6 MB on disk
Likes
0
Public
Click a slice to open those files.
.pth44.8 MB · 50%
From the Hugging Face model README
Accuracy: 91.07% on test set
Production model for detecting 7 maize diseases/pests in Ghana (Ashanti & Brong-Ahafo regions).
import torch
import torchvision.models as models
from torchvision import transforms
from PIL import Image
# Load model
checkpoint = torch.load('model.pth')
model = models.resnet18()
model.fc = torch.nn.Linear(512, 7)
model.load_state_dict(checkpoint['state_dict'])
model.eval()
# Preprocess image
transform = transforms.Compose([
transforms.Resize(256),
transforms.CenterCrop(224),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225])
])
# Predict
img = Image.open('maize_leaf.jpg').convert('RGB')
img_tensor = transform(img).unsqueeze(0)
with torch.no_grad():
output = model(img_tensor)
probabilities = torch.nn.functional.softmax(output[0], dim=0)
pred_class = output.argmax(1).item()
print(f"Prediction: {checkpoint['class_names'][pred_class]}")
print(f"Confidence: {probabilities[pred_class]:.2%}")