File size: 1,112 Bytes
831b2b6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
---
license: apache-2.0
tags: [image-classification, food, binary-classification, vit, mobile]
---
# Binary Healthy/Unhealthy Food Classifier — ViT-B/16

Frozen ViT-B/16 + linear head. Trained on [ethz/food101](https://huggingface.co/datasets/ethz/food101).

## Test metrics
- accuracy: **0.8088**
- macro F1: **0.8033**
- ROC-AUC: **0.8854**

## Files
| File | Format | Use |
|---|---|---|
| `best.pth` | PyTorch state dict | training / fine-tuning |
| `model.torchscript.pt` | TorchScript | server / LibTorch |
| `model_mobile.ptl` | TorchScript Lite | **iOS / Android** (PyTorch Mobile) |
| `model.onnx` | ONNX | Core ML, TFLite (via onnx2tf), ONNX Runtime Mobile |

## Inference (Python)
```python
import torch, torchvision.transforms as T
from PIL import Image
m = torch.jit.load("model.torchscript.pt").eval()
tf = T.Compose([T.Resize((224,224)), T.ToTensor(),
                T.Normalize([0.485,0.456,0.406],[0.229,0.224,0.225])])
img = tf(Image.open("food.jpg").convert("RGB")).unsqueeze(0)
probs = torch.softmax(m(img), dim=-1)[0]
print({"healthy": probs[0].item(), "unhealthy": probs[1].item()})
```