Image Classification
timm
Safetensors

Use manual for LUNIT_DINO

#1
by Helly123 - opened

Can someone guide me on how to apply this to my dataset?

Hi @Helly123 !

The Model card provides a simple code example to compute the embeddings of an image:

from urllib.request import urlopen
from PIL import Image
import timm

# get example histology image
img = Image.open(
  urlopen(
    "https://github.com/owkin/HistoSSLscaling/raw/main/assets/example.tif"
  )
)

# load model from the hub
model = timm.create_model(
  model_name="hf-hub:1aurent/vit_small_patch8_224.lunit_dino",
  pretrained=True,
).eval()

# get model specific transforms (normalization, resize)
data_config = timm.data.resolve_model_data_config(model)
transforms = timm.data.create_transform(**data_config, is_training=False)

output = model(transforms(img).unsqueeze(0))  # output is (batch_size, num_features) shaped tensor

To compute the embeddings of every image in your dataset, you can simply for loop the above code on each of your images.

1aurent changed discussion status to closed

Sign up or log in to comment