Downloads · 30 days
0
Piyu12/fruit-veg-freshness-mobilenetv2
fruit-veg-freshness-mobilenetv2 is a image classification model from Piyu12. Use it when you need a label for an image. The card lists the license as apache-2.0.
Fine-tuned MobileNetV2 for binary classification of fruit/vegetable freshness (fresh vs stale).
Downloads · 30 days
0
Access
Public
Updated Aug 26, 2026
Repo size
18.7 MB
Likes
1
Public
Click a slice to open those files.
.pt9.5 MB · 51%
From the Hugging Face model README
Fine-tuned MobileNetV2 for binary classification of fruit/vegetable freshness (fresh vs stale).
import torch
from torchvision import models, transforms
from PIL import Image
model = models.mobilenet_v2()
model.classifier = torch.nn.Sequential(
torch.nn.Dropout(0.3),
torch.nn.Linear(model.classifier[1].in_features, 2)
)
model.load_state_dict(torch.load("freshness_mobilenetv2_state_dict.pth", map_location="cpu"))
model.eval()
transform = transforms.Compose([
transforms.Resize((224, 224)),
transforms.ToTensor(),
transforms.Normalize([0.485, 0.456, 0.406], [0.229, 0.224, 0.225]),
])
img = Image.open("test.jpg").convert("RGB")
x = transform(img).unsqueeze(0)
with torch.no_grad():
output = model(x)
pred = torch.argmax(output, dim=1).item()
label = "fresh" if pred == 0 else "stale"
print(label)