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
Inference Providers NEW
This model isn't deployed by any Inference Provider. π Ask for provider support