Image Classification
Transformers
Safetensors
PyTorch
food-recognition
dinov3
vision-transformer
tsotsa-img
Instructions to use anonymous-eval/food-recognition with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use anonymous-eval/food-recognition with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-classification", model="anonymous-eval/food-recognition") pipe("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/hub/parrots.png")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("anonymous-eval/food-recognition", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload dinov3_custom food classifier from run 3: eps_8
Browse files- README.md +171 -0
- all_results.json +17 -17
- backbone/model.safetensors +1 -1
- classifier.pt +1 -1
- eval_results.json +7 -7
- model.safetensors +1 -1
- run_summary.json +26 -26
- train_results.json +10 -10
- trainer_log_history.json +0 -0
README.md
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
library_name: transformers
|
| 4 |
+
pipeline_tag: image-classification
|
| 5 |
+
base_model: facebook/dinov3-vitl16-pretrain-lvd1689m
|
| 6 |
+
tags:
|
| 7 |
+
- image-classification
|
| 8 |
+
- food-recognition
|
| 9 |
+
- dinov3
|
| 10 |
+
- vision-transformer
|
| 11 |
+
- pytorch
|
| 12 |
+
- tsotsa-img
|
| 13 |
+
datasets:
|
| 14 |
+
- TSOTSA-Img
|
| 15 |
+
metrics:
|
| 16 |
+
- accuracy
|
| 17 |
+
- f1
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
# DINOv3-food
|
| 21 |
+
|
| 22 |
+
DINOv3-food is a food image recognition model fine-tuned from
|
| 23 |
+
[`facebook/dinov3-vitl16-pretrain-lvd1689m`](https://huggingface.co/facebook/dinov3-vitl16-pretrain-lvd1689m)
|
| 24 |
+
on TSOTSA-Img, a merged food image dataset built from AFD, FruitVeg-81,
|
| 25 |
+
Food-101, and UECFood256.
|
| 26 |
+
|
| 27 |
+
The model predicts 389 food categories and uses a DINOv3 ViT-L/16 backbone
|
| 28 |
+
with a lightweight linear classification head.
|
| 29 |
+
|
| 30 |
+
## Dataset
|
| 31 |
+
|
| 32 |
+
TSOTSA-Img is the merged dataset used for food recognition in this work. It is
|
| 33 |
+
split into training and test subsets:
|
| 34 |
+
|
| 35 |
+
- Training split: used to fine-tune the model.
|
| 36 |
+
- Test split: used for final evaluation.
|
| 37 |
+
|
| 38 |
+
The merged dataset combines food images and labels from:
|
| 39 |
+
|
| 40 |
+
- AFD
|
| 41 |
+
- FruitVeg-81
|
| 42 |
+
- Food-101
|
| 43 |
+
- UECFood256
|
| 44 |
+
|
| 45 |
+
## Training
|
| 46 |
+
|
| 47 |
+
The selected checkpoint was fine-tuned for 8 epochs.
|
| 48 |
+
|
| 49 |
+
| Setting | Value |
|
| 50 |
+
|---|---:|
|
| 51 |
+
| Base model | `facebook/dinov3-vitl16-pretrain-lvd1689m` |
|
| 52 |
+
| Backbone | DINOv3 ViT-L/16 |
|
| 53 |
+
| Number of labels | 389 |
|
| 54 |
+
| Epochs | 8 |
|
| 55 |
+
| Batch size | 16 |
|
| 56 |
+
| Learning rate | `2e-5` |
|
| 57 |
+
| Weight decay | `0.01` |
|
| 58 |
+
| Warmup ratio | `0.05` |
|
| 59 |
+
| Validation selection | best validation behavior, with emphasis on validation loss |
|
| 60 |
+
|
| 61 |
+
Validation metrics for the selected run:
|
| 62 |
+
|
| 63 |
+
| Metric | Value |
|
| 64 |
+
|---|---:|
|
| 65 |
+
| Validation loss | 0.1100 |
|
| 66 |
+
| Accuracy | 0.9731 |
|
| 67 |
+
| Macro-F1 | 0.9727 |
|
| 68 |
+
| Top-5 accuracy | 0.9968 |
|
| 69 |
+
|
| 70 |
+
## Evaluation
|
| 71 |
+
|
| 72 |
+
Final evaluation was performed on the individual source datasets and on the
|
| 73 |
+
merged TSOTSA-Img test split.
|
| 74 |
+
|
| 75 |
+
| Dataset | Accuracy |
|
| 76 |
+
|---|---:|
|
| 77 |
+
| FruitVeg-81 | 0.9976 |
|
| 78 |
+
| AFD | 0.9997 |
|
| 79 |
+
| Food-101 | 0.9551 |
|
| 80 |
+
| UECFood256 | 0.8215 |
|
| 81 |
+
| TSOTSA-Img test | 0.9062 |
|
| 82 |
+
|
| 83 |
+
For the TSOTSA-Img test split:
|
| 84 |
+
|
| 85 |
+
| Metric | Value |
|
| 86 |
+
|---|---:|
|
| 87 |
+
| Accuracy | 0.9062 |
|
| 88 |
+
| Macro-F1 | 0.9072 |
|
| 89 |
+
|
| 90 |
+
## Model format
|
| 91 |
+
|
| 92 |
+
This repository stores a custom backbone-plus-classifier model:
|
| 93 |
+
|
| 94 |
+
- `backbone/`: DINOv3 backbone saved with `transformers`.
|
| 95 |
+
- `classifier.pt`: linear classification head.
|
| 96 |
+
- `classifier_config.json`: label mappings and classifier metadata.
|
| 97 |
+
- `preprocessor_config.json`: image preprocessing configuration.
|
| 98 |
+
|
| 99 |
+
Because this model uses a custom wrapper around the DINOv3 backbone, loading it
|
| 100 |
+
with `AutoModelForImageClassification.from_pretrained(...)` is not sufficient.
|
| 101 |
+
Use the project loader or reconstruct the wrapper before inference.
|
| 102 |
+
|
| 103 |
+
## Usage
|
| 104 |
+
|
| 105 |
+
Example with the project inference class:
|
| 106 |
+
|
| 107 |
+
```python
|
| 108 |
+
from inference.food_classifier import FoodClassifier
|
| 109 |
+
|
| 110 |
+
model_dir = "model_saved/finetuning/facebook-dinov3-vitl16-pretrain-lvd1689m/epochs_8"
|
| 111 |
+
classifier = FoodClassifier(model_dir)
|
| 112 |
+
|
| 113 |
+
prediction = classifier.predict("path/to/food_image.jpg")
|
| 114 |
+
print(prediction)
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
Manual loading:
|
| 118 |
+
|
| 119 |
+
```python
|
| 120 |
+
import json
|
| 121 |
+
import torch
|
| 122 |
+
from transformers import AutoImageProcessor, AutoModel
|
| 123 |
+
from finetuning.train_classifier import BackboneImageClassifier
|
| 124 |
+
|
| 125 |
+
model_dir = "model_saved/finetuning/facebook-dinov3-vitl16-pretrain-lvd1689m/epochs_8"
|
| 126 |
+
|
| 127 |
+
with open(f"{model_dir}/classifier_config.json", "r", encoding="utf-8") as f:
|
| 128 |
+
classifier_config = json.load(f)
|
| 129 |
+
|
| 130 |
+
id2label = {
|
| 131 |
+
int(label_id): label
|
| 132 |
+
for label_id, label in classifier_config["id2label"].items()
|
| 133 |
+
}
|
| 134 |
+
label2id = {
|
| 135 |
+
label: int(label_id)
|
| 136 |
+
for label, label_id in classifier_config["label2id"].items()
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
backbone = AutoModel.from_pretrained(f"{model_dir}/backbone")
|
| 140 |
+
model = BackboneImageClassifier(
|
| 141 |
+
backbone=backbone,
|
| 142 |
+
num_labels=int(classifier_config["num_labels"]),
|
| 143 |
+
id2label=id2label,
|
| 144 |
+
label2id=label2id,
|
| 145 |
+
)
|
| 146 |
+
|
| 147 |
+
classifier_state = torch.load(f"{model_dir}/classifier.pt", map_location="cpu")
|
| 148 |
+
model.classifier.load_state_dict(classifier_state)
|
| 149 |
+
model.eval()
|
| 150 |
+
|
| 151 |
+
processor = AutoImageProcessor.from_pretrained(model_dir)
|
| 152 |
+
```
|
| 153 |
+
|
| 154 |
+
## Intended use
|
| 155 |
+
|
| 156 |
+
This model is intended for food image recognition over the TSOTSA-Img label
|
| 157 |
+
space. It can be used for research experiments, dataset benchmarking, and food
|
| 158 |
+
recognition pipelines where the target labels overlap with the 389 supported
|
| 159 |
+
categories.
|
| 160 |
+
|
| 161 |
+
## Limitations
|
| 162 |
+
|
| 163 |
+
- The model is restricted to the 389 labels in `classifier_config.json`.
|
| 164 |
+
- Performance may degrade on food categories outside the TSOTSA-Img label
|
| 165 |
+
space.
|
| 166 |
+
- Predictions may be sensitive to ambiguous images, mixed dishes, heavy
|
| 167 |
+
occlusion, or visually similar food categories.
|
| 168 |
+
- The model card reports accuracy on the available benchmark splits and should
|
| 169 |
+
not be interpreted as performance on all possible food domains.
|
| 170 |
+
|
| 171 |
+
## Citation
|
all_results.json
CHANGED
|
@@ -1,21 +1,21 @@
|
|
| 1 |
{
|
| 2 |
"epoch": 8.0,
|
| 3 |
-
"eval_accuracy": 0.
|
| 4 |
-
"eval_f1_macro": 0.
|
| 5 |
-
"eval_loss": 0.
|
| 6 |
-
"eval_runtime":
|
| 7 |
-
"eval_samples_per_second":
|
| 8 |
-
"eval_steps_per_second":
|
| 9 |
-
"eval_top5_accuracy": 0.
|
| 10 |
-
"run_wall_time_hours":
|
| 11 |
-
"run_wall_time_minutes":
|
| 12 |
-
"run_wall_time_seconds":
|
| 13 |
"total_flos": 0.0,
|
| 14 |
-
"train_loss": 0.
|
| 15 |
-
"train_runtime":
|
| 16 |
-
"train_samples_per_second":
|
| 17 |
-
"train_steps_per_second":
|
| 18 |
-
"train_wall_time_hours":
|
| 19 |
-
"train_wall_time_minutes":
|
| 20 |
-
"train_wall_time_seconds":
|
| 21 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"epoch": 8.0,
|
| 3 |
+
"eval_accuracy": 0.9730591259640102,
|
| 4 |
+
"eval_f1_macro": 0.9727023139698624,
|
| 5 |
+
"eval_loss": 0.11002838611602783,
|
| 6 |
+
"eval_runtime": 216.4171,
|
| 7 |
+
"eval_samples_per_second": 134.809,
|
| 8 |
+
"eval_steps_per_second": 8.428,
|
| 9 |
+
"eval_top5_accuracy": 0.996846615252785,
|
| 10 |
+
"run_wall_time_hours": 10.413995842536291,
|
| 11 |
+
"run_wall_time_minutes": 624.8397505521774,
|
| 12 |
+
"run_wall_time_seconds": 37490.385033130646,
|
| 13 |
"total_flos": 0.0,
|
| 14 |
+
"train_loss": 0.37596295774437,
|
| 15 |
+
"train_runtime": 37253.6996,
|
| 16 |
+
"train_samples_per_second": 56.386,
|
| 17 |
+
"train_steps_per_second": 3.524,
|
| 18 |
+
"train_wall_time_hours": 10.348306588000721,
|
| 19 |
+
"train_wall_time_minutes": 620.8983952800432,
|
| 20 |
+
"train_wall_time_seconds": 37253.9037168026
|
| 21 |
}
|
backbone/model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 1212559808
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:4623464dfa91314a072783b772355546571b4ce0d54bc17287e7c464c84e26e7
|
| 3 |
size 1212559808
|
classifier.pt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 1596861
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e5941cc94cb6e61f79a00830562beb2356b174bda58772243d6b8fef29407777
|
| 3 |
size 1596861
|
eval_results.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
| 1 |
{
|
| 2 |
"epoch": 8.0,
|
| 3 |
-
"eval_accuracy": 0.
|
| 4 |
-
"eval_f1_macro": 0.
|
| 5 |
-
"eval_loss": 0.
|
| 6 |
-
"eval_runtime":
|
| 7 |
-
"eval_samples_per_second":
|
| 8 |
-
"eval_steps_per_second":
|
| 9 |
-
"eval_top5_accuracy": 0.
|
| 10 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"epoch": 8.0,
|
| 3 |
+
"eval_accuracy": 0.9730591259640102,
|
| 4 |
+
"eval_f1_macro": 0.9727023139698624,
|
| 5 |
+
"eval_loss": 0.11002838611602783,
|
| 6 |
+
"eval_runtime": 216.4171,
|
| 7 |
+
"eval_samples_per_second": 134.809,
|
| 8 |
+
"eval_steps_per_second": 8.428,
|
| 9 |
+
"eval_top5_accuracy": 0.996846615252785
|
| 10 |
}
|
model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 1214158628
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a8b6e793374a9998ffd81330b87bc3e5ea7d675652abed91c317a66d6a8a71e1
|
| 3 |
size 1214158628
|
run_summary.json
CHANGED
|
@@ -6,37 +6,37 @@
|
|
| 6 |
"output_dir": "./model_saved/finetuning/facebook-dinov3-vitl16-pretrain-lvd1689m/epochs_8",
|
| 7 |
"logging_dir": "./finetuning/logs/runs/facebook-dinov3-vitl16-pretrain-lvd1689m/epochs_8",
|
| 8 |
"cache_dir": "./cached_dataset/finetuning/facebook-dinov3-vitl16-pretrain-lvd1689m",
|
| 9 |
-
"started_at": "2026-06-
|
| 10 |
-
"train_finished_at": "2026-06-
|
| 11 |
-
"finished_at": "2026-06-
|
| 12 |
-
"train_duration_seconds":
|
| 13 |
-
"train_duration_minutes":
|
| 14 |
-
"train_duration_hours":
|
| 15 |
-
"run_duration_seconds":
|
| 16 |
-
"run_duration_minutes":
|
| 17 |
-
"run_duration_hours":
|
| 18 |
"train_metrics": {
|
| 19 |
-
"train_runtime":
|
| 20 |
-
"train_samples_per_second":
|
| 21 |
-
"train_steps_per_second":
|
| 22 |
"total_flos": 0.0,
|
| 23 |
-
"train_loss": 0.
|
| 24 |
"epoch": 8.0,
|
| 25 |
-
"train_wall_time_seconds":
|
| 26 |
-
"train_wall_time_minutes":
|
| 27 |
-
"train_wall_time_hours":
|
| 28 |
-
"run_wall_time_seconds":
|
| 29 |
-
"run_wall_time_minutes":
|
| 30 |
-
"run_wall_time_hours":
|
| 31 |
},
|
| 32 |
"eval_metrics": {
|
| 33 |
-
"eval_loss": 0.
|
| 34 |
-
"eval_accuracy": 0.
|
| 35 |
-
"eval_f1_macro": 0.
|
| 36 |
-
"eval_top5_accuracy": 0.
|
| 37 |
-
"eval_runtime":
|
| 38 |
-
"eval_samples_per_second":
|
| 39 |
-
"eval_steps_per_second":
|
| 40 |
"epoch": 8.0
|
| 41 |
}
|
| 42 |
}
|
|
|
|
| 6 |
"output_dir": "./model_saved/finetuning/facebook-dinov3-vitl16-pretrain-lvd1689m/epochs_8",
|
| 7 |
"logging_dir": "./finetuning/logs/runs/facebook-dinov3-vitl16-pretrain-lvd1689m/epochs_8",
|
| 8 |
"cache_dir": "./cached_dataset/finetuning/facebook-dinov3-vitl16-pretrain-lvd1689m",
|
| 9 |
+
"started_at": "2026-06-16T11:27:32.527592+00:00",
|
| 10 |
+
"train_finished_at": "2026-06-16T21:48:26.431336+00:00",
|
| 11 |
+
"finished_at": "2026-06-16T21:52:22.912657+00:00",
|
| 12 |
+
"train_duration_seconds": 37253.9037168026,
|
| 13 |
+
"train_duration_minutes": 620.8983952800432,
|
| 14 |
+
"train_duration_hours": 10.348306588000721,
|
| 15 |
+
"run_duration_seconds": 37490.385033130646,
|
| 16 |
+
"run_duration_minutes": 624.8397505521774,
|
| 17 |
+
"run_duration_hours": 10.413995842536291,
|
| 18 |
"train_metrics": {
|
| 19 |
+
"train_runtime": 37253.6996,
|
| 20 |
+
"train_samples_per_second": 56.386,
|
| 21 |
+
"train_steps_per_second": 3.524,
|
| 22 |
"total_flos": 0.0,
|
| 23 |
+
"train_loss": 0.37596295774437,
|
| 24 |
"epoch": 8.0,
|
| 25 |
+
"train_wall_time_seconds": 37253.9037168026,
|
| 26 |
+
"train_wall_time_minutes": 620.8983952800432,
|
| 27 |
+
"train_wall_time_hours": 10.348306588000721,
|
| 28 |
+
"run_wall_time_seconds": 37490.385033130646,
|
| 29 |
+
"run_wall_time_minutes": 624.8397505521774,
|
| 30 |
+
"run_wall_time_hours": 10.413995842536291
|
| 31 |
},
|
| 32 |
"eval_metrics": {
|
| 33 |
+
"eval_loss": 0.11002838611602783,
|
| 34 |
+
"eval_accuracy": 0.9730591259640102,
|
| 35 |
+
"eval_f1_macro": 0.9727023139698624,
|
| 36 |
+
"eval_top5_accuracy": 0.996846615252785,
|
| 37 |
+
"eval_runtime": 216.4171,
|
| 38 |
+
"eval_samples_per_second": 134.809,
|
| 39 |
+
"eval_steps_per_second": 8.428,
|
| 40 |
"epoch": 8.0
|
| 41 |
}
|
| 42 |
}
|
train_results.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
| 1 |
{
|
| 2 |
"epoch": 8.0,
|
| 3 |
-
"run_wall_time_hours":
|
| 4 |
-
"run_wall_time_minutes":
|
| 5 |
-
"run_wall_time_seconds":
|
| 6 |
"total_flos": 0.0,
|
| 7 |
-
"train_loss": 0.
|
| 8 |
-
"train_runtime":
|
| 9 |
-
"train_samples_per_second":
|
| 10 |
-
"train_steps_per_second":
|
| 11 |
-
"train_wall_time_hours":
|
| 12 |
-
"train_wall_time_minutes":
|
| 13 |
-
"train_wall_time_seconds":
|
| 14 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"epoch": 8.0,
|
| 3 |
+
"run_wall_time_hours": 10.413995842536291,
|
| 4 |
+
"run_wall_time_minutes": 624.8397505521774,
|
| 5 |
+
"run_wall_time_seconds": 37490.385033130646,
|
| 6 |
"total_flos": 0.0,
|
| 7 |
+
"train_loss": 0.37596295774437,
|
| 8 |
+
"train_runtime": 37253.6996,
|
| 9 |
+
"train_samples_per_second": 56.386,
|
| 10 |
+
"train_steps_per_second": 3.524,
|
| 11 |
+
"train_wall_time_hours": 10.348306588000721,
|
| 12 |
+
"train_wall_time_minutes": 620.8983952800432,
|
| 13 |
+
"train_wall_time_seconds": 37253.9037168026
|
| 14 |
}
|
trainer_log_history.json
CHANGED
|
The diff for this file is too large to render.
See raw diff
|
|
|