
<!-- 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. -->

# vit-butterflies-google-final

This is a fine-tuned version of base model: [google/vit-base-patch16-224-in21k](https://huggingface.co/google/vit-base-patch16-224-in21k) on the butterflies dataset below.

It achieved the following results on the evaluation set:
- Loss: 0.0294
- Accuracy: 0.992

**Notice:** This is the second fine-tuned version based on a previous version which had been trained on dataset once. The difference of two version lied in the image augmentation step before training, leading to the better performance of this final version.

Source code for training and predict availabel on [Github](https://github.com/hieulhaiwork/butterflies-classification)

## Datasets

This is an open dataset avilabel on [butterfly-image-classification](https://www.kaggle.com/datasets/phucthaiv02/butterfly-image-classification).

The dataset features 75 different classes of Butterflies. The dataset contains about 1000+ labelled images including the validation images. Each image belongs to only one butterfly category.

## Model description

The structure of model was kept the same as original Google's model.

## How to use

This is how to use model in Pytorch:

```(python)
from transformers import AutoFeatureExtractor, ViTForImageClassification
from PIL import Image
import requests

model_name = "hieulhwork24/vit-butterflies-google-final"
processor = AutoFeatureExtractor.from_pretrained(model_name)
model = ViTForImageClassification.from_pretrained(model_name)
inputs = processor(images=image, return_tensors="pt")

outputs = model(**inputs)
last_hidden_states = outputs.last_hidden_state
```

## Training procedure

### Training hyperparameters

The following hyperparameters were used during training:
- learning_rate: 0.0002
- train_batch_size: 32
- eval_batch_size: 8
- seed: 42
- optimizer: Use OptimizerNames.ADAMW_TORCH with betas=(0.9,0.999) and epsilon=1e-08 and optimizer_args=No additional optimizer arguments
- lr_scheduler_type: linear
- num_epochs: 5
- mixed_precision_training: Native AMP

### Training results

| Training Loss | Epoch | Step | Validation Loss | Accuracy |
|:-------------:|:-----:|:----:|:---------------:|:--------:|
| 0.1228        | 0.8   | 100  | 0.0360          | 0.989    |
| 0.0845        | 1.6   | 200  | 0.0828          | 0.983    |
| 0.046         | 2.4   | 300  | 0.0315          | 0.993    |
| 0.0223        | 3.2   | 400  | 0.0449          | 0.985    |
| 0.0221        | 4.0   | 500  | 0.0309          | 0.99     |
| 0.0092        | 4.8   | 600  | 0.0294          | 0.992    |


### Framework versions

- Transformers 4.48.3
- Pytorch 2.5.1+cu124
- Datasets 3.3.2
- Tokenizers 0.21.0
adonis african giant swallowtail blue morpho blue spotted crow brown siproeta cabbage white cairns birdwing checquered skipper chestnut cleopatra clodius parnassian clouded sulphur american snoot common banded awl common wood-nymph copper tail crecent crimson patch danaid eggfly eastern coma eastern dapple white eastern pine elfin elbowed pierrot an 88 gold banded great eggfly great jay green celled cattleheart grey hairstreak indra swallow iphiclus sister julia large marble malachite appollo mangrove skipper mestra metalmark milberts tortoiseshell monarch mourning cloak orange oakleaf orange tip orchard swallow painted lady atala paper kite peacock pine white pipevine swallow popinjay purple hairstreak purplish copper question mark red admiral red cracker banded orange heliconian red postman red spotted purple scarce swallow silver spot skipper sleepy orange sootywing southern dogface straited queen tropical leafwing two barred flasher banded peacock ulyses viceroy wood satyr yellow swallow tail zebra long wing beckers white black hairstreak