Ir para o conteúdo
ModelListadosExterno
Baixar

Food Freshness Detector

A ResNet18 image classifier trained with FastAI that predicts the freshness of fruits and vegetables.

TipoOtherVersãoRevision 7488ca2Bnota

Fonte do modelo

Tipo
Other
Tamanho do arquivo
44,7 MB
Versão
vRevision 7488ca2
Atualizado
22 de out. de 2026
Downloads
160
Fonte
Hugging Face

Descrição da fonte

Food Freshness Detector

A ResNet18 image classifier trained with FastAI that predicts the freshness of fruits and vegetables.

Classes: Fresh · Slightly Spoiled · Rotten

Usage

import json
import torch
from fastai.vision.all import create_cnn_model, resnet18
from torchvision import transforms
from PIL import Image
from huggingface_hub import hf_hub_download

# Download weights
weights_path = hf_hub_download("nathansekar/food-freshness-detector", "model_weights.pth")
config_path  = hf_hub_download("nathansekar/food-freshness-detector", "config.json")
vocab_path   = hf_hub_download("nathansekar/food-freshness-detector", "vocab.json")

with open(config_path) as f:
    config = json.load(f)
with open(vocab_path) as f:
    vocab = json.load(f)

model = create_cnn_model(resnet18, config["n_classes"])
model.load_state_dict(torch.load(weights_path, map_location="cpu"))
model.eval()

preprocess = transforms.Compose([
    transforms.Resize(256),
    transforms.CenterCrop(224),
    transforms.ToTensor(),
    transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])

image = Image.open("your_food_image.jpg").convert("RGB")
tensor = preprocess(image).unsqueeze(0)

with torch.no_grad():
    probs = torch.softmax(model(tensor), dim=1)[0]

pred_idx = probs.argmax().item()
print(f"Prediction: {vocab[pred_idx]} ({probs[pred_idx]:.1%})")

Model Details

ArchitectureResNet18 (transfer learning)
FrameworkFastAI 2.x / PyTorch
InputRGB image → 224×224
Output3-class softmax
Training dataSynthetic fruit/vegetable images

Files

FileDescription
model_weights.pthTrained ResNet18 state dict
config.jsonArchitecture config (arch, n_classes, img_size)
vocab.jsonClass label list

Fontes

1 fonte
Hugging FacePrimárioVersão 7488ca2d7204656f2f5b464e1a295871396a513d
huggingface.co/nathansekar/food-freshness-detector/tree/7488ca2d7204656f2f5b464e1a295871396a513d

Verificado 22 de out.

Artefatos de modelo

1 artefato

model_weights.pth

pth · 44,7 MB · SHA-256 61334d5fa30b…6dea · Hugging Face

Baixar

Trechos de fonte

3 trechos

--- language: en license: mit tags: - image-classification - food - freshness - fastai - pytorch - resnet library_name: fastai --- # Food Freshness Detector A ResNet18 image classifier trained with FastAI that predicts the freshness of fruits and vegetables. **Classes:** Fresh · Slightly Spoiled · Rotten ## Usage ```python import json import torch from fastai.vision.all import create_cnn_model, resnet18 from torchvision import transforms from PIL import Image from huggingface_hub import hf_hub_download # Download weights weights_path = hf_hub_download("nathansekar/food-freshness-detector", "model_weights.pth") config_path = hf_hub_download("nathansekar/food-freshness-detector", "config.json") vocab_path = hf_hub_download("nathansekar/food-freshness-detector", "vocab.json") with open(config_path) as f: config = json.load(f) with open(vocab_path) as f: vocab = json.load(f) model = create_cnn_model(resnet18, config["n_classes"]) model.load_state_dict(torch.load(weights_path, map_location="cpu")) model.eval() preprocess = transforms.Compose([ transforms.Resize(256), transforms.CenterCrop(224), transforms.ToTensor(), transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]), ]) image = Image.open("your_food_image.jpg").convert("RGB") tensor = preprocess(image).unsqueeze(0) with torch.no_grad(): probs = torch.softmax(model(tensor), dim=1)[0] pred_idx = probs.argmax().item() print(f"Prediction: {vocab[pred_idx]} ({probs[pred_idx]:.1%})") ``` ## Model Details | | | |---|---| | Architecture | ResNet18 (transfer learning) | | Framework | FastAI 2.x / PyTorch | | Input | RGB image → 224×224 | | Output | 3-class softmax | | Training data | Synthetic fruit/vegetable images | ## Files | File | Description | |---|---| | `model_weights.pth` | Trained ResNet18 state dict | | `config.json` | Architecture config (`arch`, `n_classes`, `img_size`) | | `vocab.json` | Class label list |

Source context: 160 downloads · 0 likes · Pipeline image-classification · Library fastai · Repo nathansekar/food-freshness-detector

Source context: 3909 downloads · 0 likes · Pipeline image-classification · Library fastai · Repo nathansekar/food-freshness-detector