CoolFace
Modelpublic

arnabdhar/Swin-V2-base-Food

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
0likes29downloads
Model Card

<!-- This model card has been generated automatically according to the information the Trainer had access to. You should probably proofread and complete it, then remove this comment. -->

Swin-V2-base-Food

This model is a fine-tuned version of microsoft/swinv2-base-patch4-window8-256 on the ItsNotRohit/Food121-224 dataset. It achieves the following results on the evaluation set:

  • Loss: 0.7099
  • Accuracy: 0.8160
  • Recall: 0.8160
  • Precision: 0.8168
  • F1: 0.8159

Model description

Swin v2 is a powerful vision model based on Transformers, achieving top-notch accuracy in image classification tasks. It excels thanks to:

  • _Hierarchical architecture_: Efficiently captures features at different scales, like CNNs.
  • _Shifted windows_: Improves information flow and reduces computational cost.
  • _Large model capacity_: Enables accurate and generalizable predictions.

Swin v2 sets new records on ImageNet, even needing 40x less data and training time than similar models. It's also versatile, tackling various vision tasks and handling large images.

The model was fine tuned on a 120 categories of food images.

To use the model use the following code snippet:

python
from transformers import pipeline
from PIL import Image

# init image classification pipeline
classifier = pipeline("image-classification", "arnabdhar/Swin-V2-base-Food")

# use pipeline for inference
image = Image.open(image_path)
results = classifier(image)

Intended uses

The model can be used for the following tasks:

  • _Food Image Classification_: Use this model to classify food images using the Transformers pipeline module.
  • _Base Model for Fine Tuning_: If you want to use this model for your own custom dataset you can surely do so by treating this model as a base model and fine tune it for your own dataset.

Training procedure

The fine tuning was done on Google Colab with a NVIDIA T4 GPU with 15GB of VRAM, the model was trained for 20,000 steps and it took ~5.5 hours for the fine tuning to complete which also included periodic evaluation of the model.

Training hyperparameters

The following hyperparameters were used during training:

  • learning_rate: 5e-05
  • trainbatchsize: 16
  • evalbatchsize: 128
  • seed: 17769929
  • optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
  • lrschedulertype: cosine
  • lrschedulerwarmup_ratio: 0.01
  • training_steps: 20000

Training results

Training LossEpochStepValidation LossAccuracyRecallPrecisionF1
1.51690.3320001.26800.67460.67460.70190.6737
1.23620.6640001.07590.71690.71690.74110.7178
1.10760.9960000.97570.74370.74370.75930.7430
0.91631.3280000.91230.76230.76230.77370.7628
0.82911.65100000.83970.78070.78070.78740.7796
0.79491.98120000.77240.79650.79650.80140.7965
0.64552.31140000.74580.80300.80300.80690.8031
0.63322.64160000.72220.81100.81100.81220.8106
0.61322.98180000.70210.81540.81540.81700.8155
0.573.31200000.70990.81600.81600.81680.8159

Framework versions

  • Transformers 4.35.2
  • Pytorch 2.1.0+cu121
  • Datasets 2.15.0
  • Tokenizers 0.15.0