Views
No views yet
git clone --no-checkout https://huggingface.co/MountSinaiCompPath/SP85M && cd SP85M && git sparse-checkout init --no-cone && git sparse-checkout set '/*' '!*.bin' && git checkout1from PIL import Image
2import numpy as np
3import vision_transformer
4import torch
5import torch.nn as nn
6import torchvision.transforms as transforms
7from huggingface_hub import PyTorchModelHubMixin
8
9class SP85M(nn.Module, PyTorchModelHubMixin):
10 def __init__(self):
11 super().__init__()
12 self.encoder = vision_transformer.vit_small(num_classes=0)
13
14 def forward(self, x):
15 return self.encoder(x)
16
17# Download up model
18model = SP85M.from_pretrained("MountSinaiCompPath/SP85M")
19
20# Set up transform
21transform = transforms.Compose([
22 transforms.ToTensor(),
23 transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225))
24])
25
26# Image
27img = np.random.randint(0, 256, size=224*224*3).reshape(224,224,3).astype(np.uint8)
28img = Image.fromarray(img)
29img = transform(img).unsqueeze(0)
30
31# Inference
32with torch.no_grad():
33 h = model(img)