CoolFace
Modelpublic

xn6o/lora-vit-large-patch16-224-in21k-r32-imagenet1k

sourceHugging Faceapache-2.0updated 11mo agoView on Hugging Face
0likes
Model Card

๐ŸŒŸ ViT-L/16 or ViT-B/16 LoRA โ€” ImageNet-1K Fine-tune (Top-1 โ‰ˆ 71%)

This repository contains LoRA fine-tuned weights for Vision Transformer (ViT) models trained on the ImageNet-1K classification dataset.

The repository includes:

  • โ€”LoRA adapter weights (query/key/value/output + MLP LoRA, r=32)
  • โ€”Classification head weights (classifier_head.pth)
  • โ€”A detailed model card (this file)

This enables loading the pretrained ViT together with LoRA and the final classifier head to reproduce the reported ImageNet-1K accuracy.


๐Ÿ“Œ Model Summary

ItemDescription
Base modelgoogle/vit-base-patch16-224 or ViT-Large-16 (depending on your version)
TaskImageNet-1K classification
DatasetILSVRC 2012 ImageNet-1K
Training methodPEFT LoRA (r=32), applied to Q/K/V/O + MLP
Trainable params~2% of total parameters
Final accuracyTop-1 โ‰ˆ 71%
Resolution224ร—224
OptimizerAdamW
Mixed precisionbf16 / fp16
Data augmentationsRandAugment, Mixup, CutMix, RandomResizedCrop

๐Ÿš€ How to Use

1๏ธโƒฃ Load the base ViT model

python
from transformers import ViTForImageClassification
from peft import PeftModel
import torch
python
base = ViTForImageClassification.from_pretrained(
    "google/vit-base-patch16-224"
)

2๏ธโƒฃ Load LoRA adapter

python
model = PeftModel.from_pretrained(
    base,
    "username/repo-name"
)

3๏ธโƒฃ Load classification head

python
state = torch.load("classifier_head.pth", map_location="cpu")
model.base_model.model.classifier.load_state_dict(state)
model.eval()

๐ŸŽฏ Intended Use

This model is designed for:

  • โ€”ImageNet-1K classification
  • โ€”Downstream dataset finetuning via LoRA
  • โ€”Feature extraction / embedding extraction
  • โ€”Transfer learning to custom datasets
  • โ€”Model compression and deployment

It is not intended for:

  • โ€”Safety-critical systems
  • โ€”Medical or legal decision making
  • โ€”Bias-sensitive applications

๐Ÿงฉ Training Details

LoRA Configuration

json
{
  "r": 32,
  "lora_alpha": 32,
  "lora_dropout": 0.05,
  "target_modules": [
    "query", "key", "value", "output.dense",
    "intermediate.dense", "output.dense"
  ]
}

LoRA is applied to:

  • โ€”Multi-head self-attention Q/K/V/O
  • โ€”MLP hidden layer (to/from dim 4096 โ†’ 1024)

Optimizer & Schedule

  • โ€”Optimizer: AdamW
  • โ€”Learning rate: 1e-4
  • โ€”Weight decay: 0.01
  • โ€”LR scheduler: cosine annealing
  • โ€”Warmup: None

๐Ÿ“š Dataset

  • โ€”ImageNet-1K (ILSVRC2012)
  • โ€”1.28M train images
  • โ€”50k validation images
  • โ€”1000 classes

๐Ÿฅ‡ Evaluation

MetricValue
Top-1 Accuracy~71%
Top-5 Accuracyoptional

Evaluation was done on the official 50k-val set.


๐Ÿ“ฆ Files Included

adapter_model.safetensors   # LoRA weights
adapter_config.json         # LoRA configuration
classifier_head.pth         # Final classification head
README.md                   # This model card

๐Ÿ“ Citation

If you use this model, please cite:

bibtex
@article{hu2021lora,
  title={LoRA: Low-Rank Adaptation of Large Language Models},
  author={Hu, Edward J. and others},
  year={2021}
}

@article{dosovitskiy2020vit,
  title={An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale},
  author={Dosovitskiy, Alexey and others},
  year={2020}
}

โš ๏ธ Limitations

  • โ€”Trained only for 224ร—224 resolution
  • โ€”May be biased to ImageNet categories
  • โ€”LoRA updates only ~2% of parameters (some categories could underfit)

โš– License

This model inherits the license of the base ViT model and LoRA implementation. Check the respective repos for details.


๐Ÿ™Œ Acknowledgements

Thanks to:

  • โ€”Google Research (ViT)
  • โ€”Hugging Face Transformers
  • โ€”PEFT Team (LoRA)
  • โ€”ImageNet dataset maintainers