Fresh-Grade: Multi-Task Vision Transformer (ViT) for Perishable Produce 🍅🍌📸
Fresh-Grade is a dual-head Vision Transformer (ViT) deep learning architecture designed for automated perishable produce inspection in quick-commerce dark stores, supermarket inbound staging, and fulfillment centers.
Given a single RGB photo of fresh produce (tomatoes, bananas, apples, leafy greens), the model outputs:
- Quality Grade: 4-class classification (
Fresh,Ripe,Overripe,Spoiled). - Days-to-Spoil: Continuous non-negative shelf-life estimate (regression via Softplus head).
Together, these predictions feed an automated Dynamic Markdown Bridge that triggers pricing markdowns (HOLD, SELL_FIRST, DISCOUNT_40, DUMP_SALVAGE) and enforces First-Expire-First-Out (FEFO) picking logic.
🎯 Model Architecture
- Backbone: Vision Transformer (ViT-B/16, patch size 16x16, 768-d embedding)
- Projection Layer: Shared representation dense block (Linear 768→768 + LayerNorm + GELU + Dropout)
- Head 1 (Quality Grade): Linear(768→256) → ReLU → Linear(256→4) → Softmax
- Head 2 (Shelf-Life Regression): Linear(768→128) → ReLU → Linear(128→1) → Softplus ($\text{days} \ge 0.0$)
- Joint Objective: $\mathcal{L} = \alpha \cdot \mathcal{L}{\text{CE}} + \beta \cdot \mathcal{L}{\text{MSE}}(\log(1 + \text{days}))$
💻 Quickstart Inference
import torch
from PIL import Image
from torchvision import transforms
# 1. Download weights from Hugging Face
from huggingface_hub import hf_hub_download
weights_path = hf_hub_download(repo_id="findsamirks/Fresh-Grade-ViT", filename="fresh_grade_multitask_vit.pt")
# 2. Define transforms
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]),
])
# 3. Load image & run forward pass
# (Refer to GitHub repository for model definition)
🌐 Live Interactive Demo
Test the model interactively on live inspection photos and synthetic produce presets: 👉 fresh-grade.streamlit.app
👨💻 Developer & Architect
Samir Sandhwar
Senior Retail Professional & Merchandising Head | Agentic AI & Data Science Engineer