model card
Browse files
README.md
ADDED
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
---
|
3 |
+
license: apache-2.0
|
4 |
+
tags:
|
5 |
+
- vision
|
6 |
+
- image-classification
|
7 |
+
datasets:
|
8 |
+
- nih-pc-chex-mimic_ch-google-openi-rsna
|
9 |
+
---
|
10 |
+
|
11 |
+
|
12 |
+
# densenet121-res224-all
|
13 |
+
|
14 |
+
A DenseNet is a type of convolutional neural network that utilises dense connections between layers, through Dense Blocks, where we connect all layers (with matching feature-map sizes) directly with each other. To preserve the feed-forward nature, each layer obtains additional inputs from all preceding layers and passes on its own feature-maps to all subsequent layers.
|
15 |
+
|
16 |
+
This model was trained on the datasets: nih-pc-chex-mimic_ch-google-openi-rsna and is described here: https://arxiv.org/abs/2002.02497
|
17 |
+
|
18 |
+
### How to use
|
19 |
+
|
20 |
+
Here is how to use this model to classify an image of xray:
|
21 |
+
|
22 |
+
```python
|
23 |
+
import urllib.request
|
24 |
+
|
25 |
+
import skimage
|
26 |
+
import torch
|
27 |
+
import torch.nn.functional as F
|
28 |
+
import torchvision
|
29 |
+
import torchvision.transforms
|
30 |
+
|
31 |
+
import torchxrayvision as xrv
|
32 |
+
|
33 |
+
model_name = "densenet121-res224-all"
|
34 |
+
|
35 |
+
img_url = "https://huggingface.co/spaces/torchxrayvision/torchxrayvision-classifier/resolve/main/16747_3_1.jpg"
|
36 |
+
img_path = "xray.jpg"
|
37 |
+
urllib.request.urlretrieve(img_url, img_path)
|
38 |
+
|
39 |
+
model = xrv.models.get_model(model_name, from_hf_hub=True)
|
40 |
+
|
41 |
+
img = skimage.io.imread(img_path)
|
42 |
+
img = xrv.datasets.normalize(img, 255)
|
43 |
+
|
44 |
+
# Check that images are 2D arrays
|
45 |
+
if len(img.shape) > 2:
|
46 |
+
img = img[:, :, 0]
|
47 |
+
if len(img.shape) < 2:
|
48 |
+
print("error, dimension lower than 2 for image")
|
49 |
+
|
50 |
+
# Add color channel
|
51 |
+
img = img[None, :, :]
|
52 |
+
|
53 |
+
transform = torchvision.transforms.Compose([xrv.datasets.XRayCenterCrop()])
|
54 |
+
|
55 |
+
img = transform(img)
|
56 |
+
|
57 |
+
with torch.no_grad():
|
58 |
+
img = torch.from_numpy(img).unsqueeze(0)
|
59 |
+
preds = model(img).cpu()
|
60 |
+
output = {
|
61 |
+
k: float(v)
|
62 |
+
for k, v in zip(xrv.datasets.default_pathologies, preds[0].detach().numpy())
|
63 |
+
}
|
64 |
+
print(output)
|
65 |
+
|
66 |
+
```
|
67 |
+
For more code examples, we refer to the [example scripts](https://github.com/kamalkraj/torchxrayvision/blob/master/scripts).
|
68 |
+
|
69 |
+
|
70 |
+
### Citation
|
71 |
+
|
72 |
+
Primary TorchXRayVision paper: [https://arxiv.org/abs/2111.00595](https://arxiv.org/abs/2111.00595)
|
73 |
+
|
74 |
+
```
|
75 |
+
Joseph Paul Cohen, Joseph D. Viviano, Paul Bertin, Paul Morrison, Parsa Torabian, Matteo Guarrera, Matthew P Lungren, Akshay Chaudhari, Rupert Brooks, Mohammad Hashir, Hadrien Bertrand
|
76 |
+
TorchXRayVision: A library of chest X-ray datasets and models.
|
77 |
+
https://github.com/mlmed/torchxrayvision, 2020
|
78 |
+
|
79 |
+
|
80 |
+
@article{Cohen2020xrv,
|
81 |
+
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},
|
82 |
+
journal = {https://github.com/mlmed/torchxrayvision},
|
83 |
+
title = {{TorchXRayVision: A library of chest X-ray datasets and models}},
|
84 |
+
url = {https://github.com/mlmed/torchxrayvision},
|
85 |
+
year = {2020}
|
86 |
+
arxivId = {2111.00595},
|
87 |
+
}
|
88 |
+
|
89 |
+
|
90 |
+
```
|
91 |
+
and this paper which initiated development of the library: [https://arxiv.org/abs/2002.02497](https://arxiv.org/abs/2002.02497)
|
92 |
+
```
|
93 |
+
Joseph Paul Cohen and Mohammad Hashir and Rupert Brooks and Hadrien Bertrand
|
94 |
+
On the limits of cross-domain generalization in automated X-ray prediction.
|
95 |
+
Medical Imaging with Deep Learning 2020 (Online: https://arxiv.org/abs/2002.02497)
|
96 |
+
|
97 |
+
@inproceedings{cohen2020limits,
|
98 |
+
title={On the limits of cross-domain generalization in automated X-ray prediction},
|
99 |
+
author={Cohen, Joseph Paul and Hashir, Mohammad and Brooks, Rupert and Bertrand, Hadrien},
|
100 |
+
booktitle={Medical Imaging with Deep Learning},
|
101 |
+
year={2020},
|
102 |
+
url={https://arxiv.org/abs/2002.02497}
|
103 |
+
}
|
104 |
+
```
|
105 |
+
|