加载中…
加载中…
model.safetensors 344 MBtraining_args.bin 5.3 kBThis model is a fine-tuned version of google/vit-base-patch16-224-in21k for food image classification.
It was fine-tuned on a 5,000-image subset of the Food-101 training split to classify images into the 101 Food-101 categories.
The model was created as a practical exercise while following the Hugging Face LLM Course.
google/vit-base-patch16-224-in21kThe model was fine-tuned on:
ethz/food101
The training notebook loads:
food = load_dataset("ethz/food101", split="train[:5000]")
food = food.train_test_split(test_size=0.2)
This produces an 80/20 split of the selected 5,000 examples:
The evaluation split is created from the same 5,000-example subset and is used during model development, so it should not be considered an untouched final benchmark.
Images are processed with the image processor associated with the base ViT checkpoint.
The training transformation applies a random resized crop, converts the image to a tensor, and normalizes it with the model image mean and standard deviation:
normalize = Normalize(
mean=image_processor.image_mean,
std=image_processor.image_std,
)
_transforms = Compose([
RandomResizedCrop(size),
ToTensor(),
normalize,
])
Batch construction uses DefaultDataCollator.
The model was fine-tuned with the Hugging Face Trainer API.
| Hyperparameter | Value |
|---|---|
| Learning rate | 5e-5 |
| Train batch size | 16 |
| Evaluation batch size | 16 |
| Gradient accumulation steps | 4 |
| Effective train batch size | 64 |
| Number of epochs | 3 |
| Seed | 42 |
| Evaluation strategy | epoch |
| Save strategy | epoch |
| LR scheduler | linear |
| Optimizer | AdamW (ADAMW_TORCH_FUSED) |
| Best-model metric | accuracy |
Accuracy was computed with the Hugging Face evaluate library.
| Epoch | Training Loss | Validation Loss | Accuracy |
|---|---|---|---|
| 1 | 2.7086 | 2.5068 | 0.818 |
| 2 | 1.8494 | 1.8022 | 0.876 |
| 3 | 1.6224 | 1.6242 | 0.896 |
Final reported evaluation results:
1.62420.896from PIL import Image
from transformers import pipeline
classifier = pipeline(
"image-classification",
model="Driw0x/my_awesome_food_model",
)
image = Image.open("food.jpg")
print(classifier(image))
import torch
from PIL import Image
from transformers import AutoImageProcessor, AutoModelForImageClassification
model_id = "Driw0x/my_awesome_food_model"
processor = AutoImageProcessor.from_pretrained(model_id)
model = AutoModelForImageClassification.from_pretrained(model_id)
image = Image.open("food.jpg").convert("RGB")
inputs = processor(image, return_tensors="pt")
with torch.no_grad():
logits = model(**inputs).logits
predicted_id = logits.argmax(-1).item()
print(model.config.id2label[predicted_id])
This model is primarily intended for:
Important limitations include:
This model was created as a course exercise and has not been validated for production or high-stakes use.
The complete training procedure is available in:
Driw0x/hf-ai-courses
Notebook:
llm-course/1-transformer-models/notebooks/image_classification.ipynb