Views
No views yet
1from urllib.request import urlopen
2from PIL import Image
3import timm
4
5# get example histology image
6img = Image.open(
7 urlopen(
8 "https://datasets-server.huggingface.co/assets/1aurent/LC25000/--/default/train/0/image/image.jpg"
9 )
10)
11
12# load model from the hub
13model = timm.create_model(
14 model_name="hf-hub:1aurent/vit_base_patch16_224.owkin_pancancer_ft_lc25000_lung",
15 pretrained=True,
16).eval()
17
18# get model specific transforms (normalization, resize)
19data_config = timm.data.resolve_model_data_config(model)
20transforms = timm.data.create_transform(**data_config, is_training=False)
21
22output = model(transforms(img).unsqueeze(0)) # unsqueeze single image into batch of 11from urllib.request import urlopen
2from PIL import Image
3import timm
4
5# get example histology image
6img = Image.open(
7 urlopen(
8 "https://datasets-server.huggingface.co/assets/1aurent/LC25000/--/default/train/0/image/image.jpg"
9 )
10)
11
12# load model from the hub
13model = timm.create_model(
14 model_name="hf-hub:1aurent/vit_base_patch16_224.owkin_pancancer_ft_lc25000_lung",
15 pretrained=True,
16 num_classes=0,
17).eval()
18
19# get model specific transforms (normalization, resize)
20data_config = timm.data.resolve_model_data_config(model)
21transforms = timm.data.create_transform(**data_config, is_training=False)
22
23output = model(transforms(img).unsqueeze(0)) # output is (batch_size, num_features) shaped tensor1@article {Filiot2023.07.21.23292757,
2 author = {Alexandre Filiot and Ridouane Ghermi and Antoine Olivier and Paul Jacob and Lucas Fidon and Alice Mac Kain and Charlie Saillard and Jean-Baptiste Schiratti},
3 title = {Scaling Self-Supervised Learning for Histopathology with Masked Image Modeling},
4 elocation-id = {2023.07.21.23292757},
5 year = {2023},
6 doi = {10.1101/2023.07.21.23292757},
7 publisher = {Cold Spring Harbor Laboratory Press},
8 URL = {https://www.medrxiv.org/content/early/2023/09/14/2023.07.21.23292757},
9 eprint = {https://www.medrxiv.org/content/early/2023/09/14/2023.07.21.23292757.full.pdf},
10 journal = {medRxiv}
11}