1from PIL import Image
2from torchvision import transforms
3import timm
4import torch
5
6# Load OmniRad-base from Hugging Face Hub
7model = timm.create_model(
8 "hf_hub:Snarcy/OmniRad-base",
9 pretrained=True,
10 num_classes=0 # return embeddings
11)
12
13model.eval()
14device = "cuda" if torch.cuda.is_available() else "cpu"
15model.to(device)
16
17# Preprocessing
18transform = transforms.Compose([
19 transforms.Resize((224, 224)),
20 transforms.ToTensor(),
21 transforms.Normalize(
22 mean=[0.485, 0.456, 0.406],
23 std=[0.229, 0.224, 0.225],
24 ),
25])
26
27# Load image
28image = Image.open("path/to/radiology_image.png").convert("RGB")
29x = transform(image).unsqueeze(0).to(device)
30
31# Extract features
32with torch.no_grad():
33 embedding = model(x) # shape: [1, 384]
34
35
This project and the released model weights are licensed under the Creative Commons
Attribution 4.0 International (CC BY 4.0) license.