1aurent's picture
Update README.md
8970eb6
|
raw
history blame
3.52 kB
metadata
tags:
  - image-classification
  - feature-extraction
  - timm
  - biology
  - cancer
  - histology
  - TIA
  - tiatoolbox
library_name: timm
pipeline_tag: image-classification
license: cc0-1.0
datasets:
  - 1aurent/PatchCamelyon

Model card for densenet161.tiatoolbox-pcam

A DenseNet image classification model.
Trained by Tissue Image Analytics (TIA) Centre on "pcam" histology patches.

Model Details

Model Usage

Image Classification

from urllib.request import urlopen
from PIL import Image
import torch.nn as nn
import timm

# get example histology image
img = Image.open(
  urlopen(
    "https://github.com/owkin/HistoSSLscaling/raw/main/assets/example.tif"
  )
)

# load model from the hub
model = timm.create_model(
  model_name="hf-hub:1aurent/densenet161.tiatoolbox-pcam",
  pretrained=True,
).eval()

# disable norm5's activation, as per torchvision's implementation
model.features.norm5.act == nn.Identity()

# get model specific transforms (normalization, resize)
data_config = timm.data.resolve_model_data_config(model)
transforms = timm.data.create_transform(**data_config, is_training=False)

data = transforms(img).unsqueeze(0) # input is a (batch_size, num_channels, img_size, img_size) shaped tensor
output = model(data)  # output is a (batch_size, num_features) shaped tensor

Image Embeddings

from urllib.request import urlopen
from PIL import Image
import torch.nn as nn
import timm

# get example histology image
img = Image.open(
  urlopen(
    "https://github.com/owkin/HistoSSLscaling/raw/main/assets/example.tif"
  )
)

# load model from the hub
model = timm.create_model(
  model_name="hf-hub:1aurent/densenet161.tiatoolbox-pcam",
  pretrained=True,
  num_classes=0,
).eval()

# disable norm5's activation, as per torchvision's implementation
model.features.norm5.act == nn.Identity()

# get model specific transforms (normalization, resize)
data_config = timm.data.resolve_model_data_config(model)
transforms = timm.data.create_transform(**data_config, is_training=False)

data = transforms(img).unsqueeze(0) # input is a (batch_size, num_channels, img_size, img_size) shaped tensor
output = model(data)  # output is a (batch_size, num_features) shaped tensor

Citation

@article{Pocock2022,
  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},
  doi       = {10.1038/s43856-022-00186-5},
  issn      = {2730-664X},
  journal   = {Communications Medicine},
  month     = {sep},
  number    = {1},
  pages     = {120},
  publisher = {Springer US},
  title     = {{TIAToolbox as an end-to-end library for advanced tissue image analytics}},
  url       = {https://www.nature.com/articles/s43856-022-00186-5},
  volume    = {2},
  year      = {2022}
}