Views
No views yet

1from PIL import Image
2import torch
3import timm
4
5# load model from the hub
6model = timm.create_model(
7 model_name="hf-hub:1aurent/vit_giant_patch14_reg4_224.h-optimus-v0",
8 pretrained=True,
9).eval()
10
11# get model specific transforms (normalization, resize)
12data_config = timm.data.resolve_model_data_config(model)
13transforms = timm.data.create_transform(**data_config, is_training=False)
14
15img = Image.open(...)
16data = transforms(img).unsqueeze(0) # input is a (batch_size, num_channels, img_size, img_size) shaped tensor
17output = model(data) # output is a (batch_size, num_features) shaped tensor1@software{hoptimus0,
2 title = {H-optimus-0},
3 author = {Saillard, Charlie and Jenatton, Rodolphe and Llinares-López, Felipe and Mariet, Zelda and Cahané, David and Durand, Eric and Vert, Jean-Philippe},
4 url = {https://github.com/bioptimus/releases/tree/main/models/h-optimus/v0},
5 year = {2024},
6}