Parameter Efficient Fine-tuning of Self-supervised ViTs without Catastrophic Forgetting

June 18, 2024 ยท View on GitHub

[PyTorch] Code for the paper - 'Parameter Efficient Fine-tuning of Self-supervised ViTs without Catastrophic Forgetting' (CVPR - eLVM 2024). Paper

img

Includes standard full model, linear probing and parameter efficient strategies like Block Expansion and LoRA for fine-tuning Vision Transformers (ViTs) for image classification.

Requirements

  • Python 3.8+
  • pip install -r requirements.txt

Available Datasets

Dataset--data.dataset
CIFAR-10cifar10
CIFAR-100cifar100
Oxford-IIIT Pet Datasetpets37
Oxford Flowers-102flowers102
Food-101food101
Describable Textures Datasetdtd
Image Foldercustom dataset

Usage:

  • config/ contains example configuration files which can be run with:
python main.py fit --config path/to/config

You can either edit the existing config for your own choice of hyperparameters or choose to do it from command line as follows:

python main.py fit --trainer.accelerator gpu --trainer.devices 1 --trainer.precision 16-mixed
--trainer.max_steps 5000 --model.warmup_steps 500 --model.lr 0.01
--trainer.val_check_interval 500 --data.batch_size 128 --data.dataset cifar100

Examples

1. Full Fine-tuning:

  • To fully fine-tune a ViT-B/16 model on Foods-101 run:
    python main.py fit --config configs/full/food101.yaml

2. Linear Probing:

  • To train linear probes on top of a ViT-B/16 model on Foods-101 run:
    python main.py fit --config configs/linear/food101.yaml

3. Low-Rank Adaptation (LoRA):

  • To fine-tuning a ViT-B/16 model using LoRA on Foods-101 run:
    python main.py fit --config configs/lora/food101.yaml

4. Block Expansion:

  • To fine-tune a ViT-B/16 model using block expansion on Foods-101 run:
    python main.py fit --config configs/block/food101.yaml

Training on a Custom Dataset

To train on a custom dataset first organize the images into Image Folder format. Then set --data.dataset custom, --data.root path/to/custom/dataset and --data.num_classes <num-dataset-classes>.

Evaluate

To evaluate a trained model on its test set, find the path of the saved config file for the checkpoint (eg. output/cifar10/version_0/config.yaml) and run:

python main.py test --ckpt_path path/to/checkpoint --config path/to/config
  • Note: Make sure the --trainer.precision argument is set to the same level as used during training.

Results

All results are from fine-tuned ViT-B/16 models which were pretrained on ImageNet-21k (--model.model_name vit-b16-224-in21k).

img2

Standard Fine-tuning

Model# ParamsCifar-100IN-1kMEANConfig
All85.9 M88.1325.2456.69Link
Top-321.3 M84.5674.1579.36Link
Linear76.9 K80.5776.1178.34Link

LoRA

Model# ParamsCifar-100IN-1kMEANConfig
r=4301 K87.9166.8277.37Link
r=8448 K88.2765.9977.13Link
r=16743 K87.8465.0676.45Link

Block Expansion

Model# ParamsCifar-100IN-1kMEANConfig
p=17.2 M82.7275.7579.24Link
p=214.3 M86.7075.5481.12Link
p=321.3 M88.5874.6181.60Link
p=428.4 M89.0972.2880.69Link

Bibtex

You can cite us using the following:

@InProceedings{Bafghi_2024_CVPR,
    author    = {Bafghi, Reza Akbarian and Harilal, Nidhin and Monteleoni, Claire and Raissi, Maziar},
    title     = {Parameter Efficient Fine-tuning of Self-supervised ViTs without Catastrophic Forgetting},
    booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR) Workshops},
    month     = {June},
    year      = {2024},
    pages     = {3679-3684}
}