Skip to content

kreshuklab/DINOv2_classifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DINOv2 Linear Classifier

This repository contains code for training a linear classifier on top of a frozen DINOv2 backbone. The project leverages Meta's DINOv2 model to extract image embeddings and applies a simple PyTorch linear layer for classification.

Project Structure

  • dino_training.py: Script for training the classifier.
  • dino_inference.py: Script for running inference.
  • .gitignore: Specifies files and directories that Git should ignore.
  • requirements.txt or environment.yml: Files to recreate the Python environment.

Setup Instructions

1. Clone the Repository

git clone https://github.com/yourusername/my_dinov2_project.git

2. Set up the environment

Using pip (virtualenv):

python -m venv venv
source venv/bin/activate   # For Linux/macOS
pip install -r requirements.txt

Using conda:

conda env create -f environment.yml
conda activate dinov2_classification

3. Training the model

An example of running the training script:

python dino_training.py \
    --data_dir /path/to/data \
    --train_percentage 0.8 \
    --save_dir ./outputs \
    --num_epochs 30 \
    --batch_size 64 \
    --lr 1e-4 \
    --device cuda:0 \
    --model_name dinov2_vits14_reg \
    --early_stopping_patience 10 \
    --seed 42

3. Running inference

Use the inference script:

python dino_inference.py \
    --inference_dir /path/to/inference/images \
    --checkpoint_path ./outputs/best_model.pth \
    --model_name dinov2_vits14_reg \
    --device cuda:0 \
    --out_file predictions.json

About

DINOv2 + linear classifier

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages