A binary image classifier for detecting food and drink in images, trained via knowledge
distillation from SigLIP2-so400m zero-shot labels on 3.1M images from
DataComp-1B-food-and-drink-3M.
Part of a 3-model portfolio for the
Nutrify food tracking pipeline.
1import timm
2import torch
3from PIL import Image
4from huggingface_hub import hf_hub_download
5from safetensors.torch import load_file
6
7# Load model
8model = timm.create_model("vit_base_patch16_siglip_256.v2_webli", pretrained=False, num_classes=2)
9weights = hf_hub_download("mrdbourke/food-not-food-classifier-siglip2-v1", "model.safetensors")
10model.load_state_dict(load_file(weights))
11model.eval()
12
13# Prepare transform (use timm's built-in config)
14from timm.data import resolve_data_config, create_transform
15data_config = resolve_data_config(model.pretrained_cfg)
16data_config["input_size"] = (3, 256, 256)
17transform = create_transform(**data_config, is_training=False)
18
19# Classify
20image = Image.open("photo.jpg").convert("RGB")
21input_tensor = transform(image).unsqueeze(0)
22
23with torch.inference_mode():
24 logits = model(input_tensor)
25 probs = torch.softmax(logits, dim=1)
26 pred = logits.argmax(dim=1).item()
27
28labels = ["food_or_drink", "not_food_or_drink"]
29print(f"{labels[pred]}: {probs[0][pred]:.1%}")
These models were trained together as part of the Nutrify food/not_food classifier portfolio.
Pick the right one for your use case:
Evaluated on 153,911 human-labeled images from the Nutrify FoodVision dataset
(118K food + 35K not_food). This is an out-of-distribution test — the model was
trained on DataComp-1B web images, not FoodVision images.
This model is part of the Nutrify VLM pipeline — a cascading filter system for building
a food/drink image dataset from billion-scale web crawls:
1@misc{food-not-food-siglip2-base-256-v1,
2 author = {Daniel Bourke},
3 title = {Food/Not Food Classifier — siglip2_base_256 v1},
4 year = {2026},
5 publisher = {HuggingFace},
6 url = {https://huggingface.co/mrdbourke/food-not-food-classifier-siglip2-v1}
7}