Fresh-Grade: Multi-Task Vision Transformer (ViT) for Perishable Produce πŸ…πŸŒπŸ“Έ

Streamlit App GitHub License: MIT

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:

  1. Quality Grade: 4-class classification (Fresh, Ripe, Overripe, Spoiled).
  2. 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

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