Downloads · 30 days
0
karlghosn/swin-b-food101
swin-b-food101 is a image classification model from karlghosn. Use it when you need a label for an image. The card lists the license as mit.
Swin-B backbone fine-tuned on the Food-101 dataset using Optuna hyperparameter optimization.
Downloads · 30 days
0
Access
Public
Updated May 16, 2026
Repo size
349 MB
Likes
0
Public
Click a slice to open those files.
.pt349 MB · 100%
From the Hugging Face model README
Swin-B backbone fine-tuned on the Food-101 dataset using Optuna hyperparameter optimization.
| Metric | Score |
|---|---|
| Top-1 Acc | 91.87% |
| Top-5 Acc | 98.76% |
| F1 | 91.85% |
| Precision | 91.91% |
| Recall | 91.87% |
Evaluated on the official Food-101 test set (25,250 images, 101 classes).
torchvision.models.swin_b (ImageNet pretrained)Hyperparameters were found via Optuna (TPE sampler, 75-epoch budget per trial).
import torch
import torch.nn as nn
import torchvision.models as tv_models
from torchvision import transforms
from huggingface_hub import hf_hub_download
from PIL import Image
# Build model
backbone = tv_models.swin_b(weights=None)
backbone.head = nn.Sequential(
nn.Flatten(1),
nn.Dropout(p=0.183),
nn.Linear(1024, 350),
nn.ReLU(inplace=True),
nn.Linear(350, 101),
)
backbone.load_state_dict(
torch.load(hf_hub_download("karlghosn/swin-b-food101", "best_model.pt"), map_location="cpu")
)
backbone.eval()
# Preprocess
transform = 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")
with torch.inference_mode():
logits = backbone(transform(image).unsqueeze(0))
probs = torch.softmax(logits, dim=1)[0]