Views
No views yet

1from urllib.request import urlopen
2from PIL import Image
3import torch.nn as nn
4import timm
5
6# get example histology image
7img = Image.open(
8 urlopen(
9 "https://github.com/owkin/HistoSSLscaling/raw/main/assets/example.tif"
10 )
11)
12
13# load model from the hub
14model = timm.create_model(
15 model_name="hf-hub:1aurent/densenet161.tiatoolbox-pcam",
16 pretrained=True,
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
23data = transforms(img).unsqueeze(0) # input is a (batch_size, num_channels, img_size, img_size) shaped tensor
24output = model(data) # output is a (batch_size, num_features) shaped tensor1from urllib.request import urlopen
2from PIL import Image
3import torch.nn as nn
4import timm
5
6# get example histology image
7img = Image.open(
8 urlopen(
9 "https://github.com/owkin/HistoSSLscaling/raw/main/assets/example.tif"
10 )
11)
12
13# load model from the hub
14model = timm.create_model(
15 model_name="hf-hub:1aurent/densenet161.tiatoolbox-pcam",
16 pretrained=True,
17 num_classes=0,
18).eval()
19
20# get model specific transforms (normalization, resize)
21data_config = timm.data.resolve_model_data_config(model)
22transforms = timm.data.create_transform(**data_config, is_training=False)
23
24data = transforms(img).unsqueeze(0) # input is a (batch_size, num_channels, img_size, img_size) shaped tensor
25output = model(data) # output is a (batch_size, num_features) shaped tensor1@article{Pocock2022,
2 author = {Pocock, Johnathan and Graham, Simon and Vu, Quoc Dang and Jahanifar, Mostafa and Deshpande, Srijay and Hadjigeorghiou, Giorgos and Shephard, Adam and Bashir, Raja Muhammad Saad and Bilal, Mohsin and Lu, Wenqi and Epstein, David and Minhas, Fayyaz and Rajpoot, Nasir M and Raza, Shan E Ahmed},
3 doi = {10.1038/s43856-022-00186-5},
4 issn = {2730-664X},
5 journal = {Communications Medicine},
6 month = {sep},
7 number = {1},
8 pages = {120},
9 publisher = {Springer US},
10 title = {{TIAToolbox as an end-to-end library for advanced tissue image analytics}},
11 url = {https://www.nature.com/articles/s43856-022-00186-5},
12 volume = {2},
13 year = {2022}
14}