Views
No views yet
all model has every output trained. However, for the other weights some targets are not trained and will predict randomly becuase they do not exist in the training dataset. The only valid outputs are listed in the field {dataset}.pathologies on the dataset that corresponds to the weights.1import urllib.request
2
3import skimage
4import torch
5import torch.nn.functional as F
6import torchvision
7import torchvision.transforms
8
9import torchxrayvision as xrv
10
11model_name = "densenet121-res224-pc"
12
13img_url = "https://huggingface.co/spaces/torchxrayvision/torchxrayvision-classifier/resolve/main/16747_3_1.jpg"
14img_path = "xray.jpg"
15urllib.request.urlretrieve(img_url, img_path)
16
17model = xrv.models.get_model(model_name, from_hf_hub=True)
18
19img = skimage.io.imread(img_path)
20img = xrv.datasets.normalize(img, 255)
21
22# Check that images are 2D arrays
23if len(img.shape) > 2:
24 img = img[:, :, 0]
25if len(img.shape) < 2:
26 print("error, dimension lower than 2 for image")
27
28# Add color channel
29img = img[None, :, :]
30
31transform = torchvision.transforms.Compose([xrv.datasets.XRayCenterCrop()])
32
33img = transform(img)
34
35with torch.no_grad():
36 img = torch.from_numpy(img).unsqueeze(0)
37 preds = model(img).cpu()
38 output = {
39 k: float(v)
40 for k, v in zip(xrv.datasets.default_pathologies, preds[0].detach().numpy())
41 }
42print(output)
43Joseph Paul Cohen, Joseph D. Viviano, Paul Bertin, Paul Morrison, Parsa Torabian, Matteo Guarrera, Matthew P Lungren, Akshay Chaudhari, Rupert Brooks, Mohammad Hashir, Hadrien Bertrand
TorchXRayVision: A library of chest X-ray datasets and models.
https://github.com/mlmed/torchxrayvision, 2020
@article{Cohen2020xrv,
author = {Cohen, Joseph Paul and Viviano, Joseph D. and Bertin, Paul and Morrison, Paul and Torabian, Parsa and Guarrera, Matteo and Lungren, Matthew P and Chaudhari, Akshay and Brooks, Rupert and Hashir, Mohammad and Bertrand, Hadrien},
journal = {https://github.com/mlmed/torchxrayvision},
title = {{TorchXRayVision: A library of chest X-ray datasets and models}},
url = {https://github.com/mlmed/torchxrayvision},
year = {2020}
arxivId = {2111.00595},
}
Joseph Paul Cohen and Mohammad Hashir and Rupert Brooks and Hadrien Bertrand
On the limits of cross-domain generalization in automated X-ray prediction.
Medical Imaging with Deep Learning 2020 (Online: https://arxiv.org/abs/2002.02497)
@inproceedings{cohen2020limits,
title={On the limits of cross-domain generalization in automated X-ray prediction},
author={Cohen, Joseph Paul and Hashir, Mohammad and Brooks, Rupert and Bertrand, Hadrien},
booktitle={Medical Imaging with Deep Learning},
year={2020},
url={https://arxiv.org/abs/2002.02497}
}