Image Classification
Transformers
vision
Inference Endpoints
kamalkraj commited on
Commit
3e7ea05
1 Parent(s): e7637aa

model card

Browse files
Files changed (1) hide show
  1. README.md +104 -0
README.md ADDED
@@ -0,0 +1,104 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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-mimic_nb
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
+
17
+ ### How to use
18
+
19
+ Here is how to use this model to classify an image of xray:
20
+
21
+ ```python
22
+ import urllib.request
23
+
24
+ import skimage
25
+ import torch
26
+ import torch.nn.functional as F
27
+ import torchvision
28
+ import torchvision.transforms
29
+
30
+ import torchxrayvision as xrv
31
+
32
+ model_name = "densenet121-res224-mimic_nb"
33
+
34
+ img_url = "https://huggingface.co/spaces/torchxrayvision/torchxrayvision-classifier/resolve/main/16747_3_1.jpg"
35
+ img_path = "xray.jpg"
36
+ urllib.request.urlretrieve(img_url, img_path)
37
+
38
+ model = xrv.models.get_model(model_name, from_hf_hub=True)
39
+
40
+ img = skimage.io.imread(img_path)
41
+ img = xrv.datasets.normalize(img, 255)
42
+
43
+ # Check that images are 2D arrays
44
+ if len(img.shape) > 2:
45
+ img = img[:, :, 0]
46
+ if len(img.shape) < 2:
47
+ print("error, dimension lower than 2 for image")
48
+
49
+ # Add color channel
50
+ img = img[None, :, :]
51
+
52
+ transform = torchvision.transforms.Compose([xrv.datasets.XRayCenterCrop()])
53
+
54
+ img = transform(img)
55
+
56
+ with torch.no_grad():
57
+ img = torch.from_numpy(img).unsqueeze(0)
58
+ preds = model(img).cpu()
59
+ output = {
60
+ k: float(v)
61
+ for k, v in zip(xrv.datasets.default_pathologies, preds[0].detach().numpy())
62
+ }
63
+ print(output)
64
+
65
+ ```
66
+ For more code examples, we refer to the [example scripts](https://github.com/kamalkraj/torchxrayvision/blob/master/scripts).
67
+
68
+
69
+ ### Citation
70
+
71
+ Primary TorchXRayVision paper: [https://arxiv.org/abs/2111.00595](https://arxiv.org/abs/2111.00595)
72
+
73
+ ```
74
+ 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
75
+ TorchXRayVision: A library of chest X-ray datasets and models.
76
+ https://github.com/mlmed/torchxrayvision, 2020
77
+
78
+
79
+ @article{Cohen2020xrv,
80
+ 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},
81
+ journal = {https://github.com/mlmed/torchxrayvision},
82
+ title = {{TorchXRayVision: A library of chest X-ray datasets and models}},
83
+ url = {https://github.com/mlmed/torchxrayvision},
84
+ year = {2020}
85
+ arxivId = {2111.00595},
86
+ }
87
+
88
+
89
+ ```
90
+ and this paper which initiated development of the library: [https://arxiv.org/abs/2002.02497](https://arxiv.org/abs/2002.02497)
91
+ ```
92
+ Joseph Paul Cohen and Mohammad Hashir and Rupert Brooks and Hadrien Bertrand
93
+ On the limits of cross-domain generalization in automated X-ray prediction.
94
+ Medical Imaging with Deep Learning 2020 (Online: https://arxiv.org/abs/2002.02497)
95
+
96
+ @inproceedings{cohen2020limits,
97
+ title={On the limits of cross-domain generalization in automated X-ray prediction},
98
+ author={Cohen, Joseph Paul and Hashir, Mohammad and Brooks, Rupert and Bertrand, Hadrien},
99
+ booktitle={Medical Imaging with Deep Learning},
100
+ year={2020},
101
+ url={https://arxiv.org/abs/2002.02497}
102
+ }
103
+ ```
104
+