CoolFace
Modelpublic

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

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
Model Card

๐Ÿงฉ ViT-Large Patch16 224 - LoRA r=96 (ImageNet-1K Finetuned)

This repository contains a LoRA finetuned version of `google/vit-large-patch16-224-in21k` for ImageNet-1K classification, using rank = 96 LoRA adapters with additional data augmentation and strong regularization. The classifier head was retrained from scratch and is provided separately.


๐Ÿ“Œ Finetuning Summary

PropertyValue
Base Modelgoogle/vit-large-patch16-224-in21k
TaskImage Classification (ImageNet-1K)
Adapter TypeLoRA
LoRA Rank96
Trainable Params~42M
Total Params~305M
Trainable Ratio~12.24%
Best Val Top-182.82%
Best Val Top-593.93%

๐Ÿ“‚ Files in Repository

FilenameDescription
adapter_model.safetensorsLoRA weights
adapter_config.jsonConfiguration for LoRA
vit_classifier_r96.ptFull classifier layer (1000 classes)

๐Ÿšจ Important Notice

This LoRA model does not include classifier weights in the adapter. To reproduce correct evaluation accuracy, you MUST load both:

1๏ธโƒฃ Base model 2๏ธโƒฃ LoRA adapter 3๏ธโƒฃ Custom classifier parameters

Failure to load the classifier will significantly reduce accuracy.


๐Ÿ“ฆ Usage Example (PyTorch)

python
import torch
from transformers import ViTForImageClassification
from peft import PeftModel

device = "cuda" if torch.cuda.is_available() else "cpu"

# 1. Load base model
model = ViTForImageClassification.from_pretrained(
    "google/vit-large-patch16-224-in21k",
    num_labels=1000
)

# 2. Load LoRA adapter
model = PeftModel.from_pretrained(model, "xn6o/lora-vit-large-patch16-224-in21k-r96-imagenet1k")

# 3. Load trained classifier weights
state_dict = torch.load("vit_classifier_r96.pt", map_location=device)
model.classifier.load_state_dict(state_dict)

model.to(device)
model.eval()

print("Model fully loaded with LoRA + classifier.")

๐Ÿ” Inference Example (Batch Images)

python
with torch.no_grad():
    outputs = model(pixel_values=images)
    preds = torch.argmax(outputs.logits, dim=-1)

๐Ÿ“ˆ Training Details

Key techniques:

  • โ€”RandAugment + ColorJitter + RandomErasing
  • โ€”Cosine LR warm restart (iteration level)
  • โ€”AMP (BF16 preferred if supported)
  • โ€”Gradient clipping

๐Ÿ“œ License

This model follows the same license as the original ViT base model from Google Research and Hugging Face Transformers. Usage must comply with ImageNet dataset license.


---


- PEFT 0.17.1