Skip to content

Commit

Permalink
move folder to this repo
Browse files Browse the repository at this point in the history
  • Loading branch information
ieee8023 committed Aug 6, 2020
1 parent 93754f8 commit fed90ed
Show file tree
Hide file tree
Showing 13 changed files with 2,061 additions and 1 deletion.
43 changes: 42 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
# covid-severity
## Predicting COVID-19 Pneumonia Severity on Chest X-ray with Deep Learning

🛑 NOT FOR MEDICAL USE 🛑

Data is here: [Pneumonia severity scores for 94 images](https://github.com/ieee8023/covid-chestxray-dataset/blob/master/annotations/covid-severity-scores.csv)

- **geographic_extent_mean**: The extent of lung involvement by ground glass opacity or consolidation for each lung. The total extent score ranged from 0 to 8.
- **opacity_mean**: The degree of opacity. The total opacity score ranged from 0 to 6.

License: CC BY-SA Creative Commons Attribution-ShareAlike

These are from the follow paper:
Cohen, Joseph Paul, et al. Predicting COVID-19 Pneumonia Severity on Chest X-Ray with Deep Learning. May 2020, http://arxiv.org/abs/2005.11856.

```
@article{Cohen2020Severity,
title = {Predicting COVID-19 Pneumonia Severity on Chest X-ray with Deep Learning},
author = {Cohen, Joseph Paul and Dao, Lan and Morrison, Paul and Roth, Karsten and Bengio, Yoshua and Shen, Beiyi and Abbasi, Almas and Hoshmand-Kochi, Mahsa and Ghassemi, Marzyeh and Li, Haifang and Duong, Tim Q},
url = {http://arxiv.org/abs/2005.11856},
year = {2020}
}
```

To run the CLI:

```
$ python predict_severity.py 2966893D-5DDF-4B68-9E2B-4979D5956C8E.jpeg
geographic_extent (0-8): 5.978744940174467
opacity (0-6): 4.169582852893416
# or to output a saliency map:
$ python predict_severity.py 01E392EE-69F9-4E33-BFCE-E5C968654078.jpeg -saliency_path heatmap.jpg
```

| Image | Saliency map | Predictions |
|-------------------------------|-------------------------------|-----------|
| ![](examples/2966893D-5DDF-4B68-9E2B-4979D5956C8E.jpeg-resize.jpg)| ![](examples/2966893D-5DDF-4B68-9E2B-4979D5956C8E.jpeg-heatmap.jpg)| geographic_extent (0-8): 5.979 <br>opacity (0-6): 4.17 |
| ![](examples/31BA3780-2323-493F-8AED-62081B9C383B.jpeg-resize.jpg)| ![](examples/31BA3780-2323-493F-8AED-62081B9C383B.jpeg-heatmap.jpg)| geographic_extent (0-8): 6.293 <br>opacity (0-6): 4.367 |
| ![](examples/41591_2020_819_Fig1_HTML.webp-day5.png-resize.jpg)| ![](examples/41591_2020_819_Fig1_HTML.webp-day5.png-heatmap.jpg)| geographic_extent (0-8): 3.067 <br>opacity (0-6): 2.335 |
| ![](examples/8FDE8DBA-CFBD-4B4C-B1A4-6F36A93B7E87.jpeg-resize.jpg)| ![](examples/8FDE8DBA-CFBD-4B4C-B1A4-6F36A93B7E87.jpeg-heatmap.jpg)| geographic_extent (0-8): 0.9483 <br>opacity (0-6): 1.0 |

100 changes: 100 additions & 0 deletions covid-severity-scores.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
## COVID-19 Pneumonia Severity Scores (Mean of 3 expert raters),,
## License: CC BY-SA Creative Commons Attribution-ShareAlike,,
## Citation: Joseph Paul Cohen et al. Predicting COVID-19 Pneumonia Severity on Chest X-Ray with Deep Learning. May 2020 http://arxiv.org/abs/2005.11856.,,
## geographic_extent_mean: The extent of lung involvement by ground glass opacity or consolidation for each lung. The total extent score ranged from 0 to 8.,,
## opacity_mean: The degree of opacity. The total opacity score ranged from 0 to 6.,,
filename,geographic_mean,opacity_mean
01E392EE-69F9-4E33-BFCE-E5C968654078.jpeg,6.0,4.0
03BF7561-A9BA-4C3C-B8A0-D3E585F73F3C.jpeg,2.7,2.0
1-s2.0-S0140673620303706-fx1_lrg.jpg,2.0,2.0
1-s2.0-S1684118220300608-main.pdf-001.jpg,3.7,3.0
1-s2.0-S1684118220300608-main.pdf-002.jpg,1.7,1.7
1-s2.0-S1684118220300682-main.pdf-002-a1.png,0.0,0.0
1-s2.0-S1684118220300682-main.pdf-002-a2.png,0.3,0.3
1-s2.0-S1684118220300682-main.pdf-003-b1.png,1.3,1.3
1-s2.0-S1684118220300682-main.pdf-003-b2.png,2.0,2.0
1.CXRCTThoraximagesofCOVID-19fromSingapore.pdf-000-fig1a.png,1.0,1.0
1.CXRCTThoraximagesofCOVID-19fromSingapore.pdf-000-fig1b.png,1.0,1.0
1.CXRCTThoraximagesofCOVID-19fromSingapore.pdf-001-fig2a.png,0.3,0.3
1.CXRCTThoraximagesofCOVID-19fromSingapore.pdf-001-fig2b.png,1.0,1.0
1.CXRCTThoraximagesofCOVID-19fromSingapore.pdf-002-fig3a.png,1.0,1.0
1.CXRCTThoraximagesofCOVID-19fromSingapore.pdf-002-fig3b.png,4.7,2.7
1.CXRCTThoraximagesofCOVID-19fromSingapore.pdf-003-fig4a.png,4.0,3.3
1.CXRCTThoraximagesofCOVID-19fromSingapore.pdf-003-fig4b.png,4.7,4.0
1312A392-67A3-4EBF-9319-810CF6DA5EF6.jpeg,4.0,3.0
1B734A89-A1BF-49A8-A1D3-66FAFA4FAC5D.jpeg,2.0,2.3
23E99E2E-447C-46E5-8EB2-D35D12473C39.png,2.0,2.0
2966893D-5DDF-4B68-9E2B-4979D5956C8E.jpeg,6.7,4.0
2C26F453-AF3B-4517-BB9E-802CF2179543.jpeg,2.3,2.0
31BA3780-2323-493F-8AED-62081B9C383B.jpeg,7.7,6.0
353889E0-A1E8-4F9E-A0B8-F24F36BCFBFB.jpeg,4.7,4.0
41591_2020_819_Fig1_HTML.webp-day10.png,2.3,2.7
41591_2020_819_Fig1_HTML.webp-day5.png,2.3,3.0
53EC07C9-5CC6-4BE4-9B6F-D7B0D72AAA7E.jpeg,5.0,3.3
58cb9263f16e94305c730685358e4e_jumbo.jpeg,1.0,1.0
6b44464d-73a7-4cf3-bbb6-ffe7168300e3.annot.original.jpeg,0.0,0.0
6C94A287-C059-46A0-8600-AFB95F4727B7.jpeg,8.0,5.0
6CB4EFC6-68FA-4CD5-940C-BEFA8DAFE9A7.jpeg,6.3,3.3
7AF6C1AF-D249-4BD2-8C26-449304105D03.jpeg,2.0,2.7
7C69C012-7479-493F-8722-ABC29C60A2DD.jpeg,0.0,0.0
80446565-E090-4187-A031-9D3CEAA586C8.jpeg,3.7,2.0
85E52EB3-56E9-4D67-82DA-DEA247C82886.jpeg,4.7,4.0
8FDE8DBA-CFBD-4B4C-B1A4-6F36A93B7E87.jpeg,0.3,0.3
93FE0BB1-022D-4F24-9727-987A07975FFB.jpeg,3.3,3.7
9C34AF49-E589-44D5-92D3-168B3B04E4A6.jpeg,1.7,1.7
9fdd3c3032296fd04d2cad5d9070d4_jumbo.jpeg,1.0,1.0
all14238-fig-0001-m-b.jpg,6.0,4.0
all14238-fig-0001-m-c.jpg,6.0,4.0
auntminnie-a-2020_01_28_23_51_6665_2020_01_28_Vietnam_coronavirus.jpeg,2.3,1.3
auntminnie-b-2020_01_28_23_51_6665_2020_01_28_Vietnam_coronavirus.jpeg,4.0,3.0
auntminnie-c-2020_01_28_23_51_6665_2020_01_28_Vietnam_coronavirus.jpeg,4.7,3.0
auntminnie-d-2020_01_28_23_51_6665_2020_01_28_Vietnam_coronavirus.jpeg,5.7,3.7
B2D20576-00B7-4519-A415-72DE29C90C34.jpeg,6.7,3.3
CD50BA96-6982-4C80-AE7B-5F67ACDBFA56.jpeg,3.0,2.7
ciaa199.pdf-001-a.png,0.0,0.0
ciaa199.pdf-001-b.png,0.0,0.0
ciaa199.pdf-001-c.png,0.0,0.0
covid-19-infection-exclusive-gastrointestinal-symptoms-pa.png,2.3,2.0
covid-19-pneumonia-12.jpg,8.0,4.0
covid-19-pneumonia-14-PA.png,3.3,2.0
covid-19-pneumonia-15-PA.jpg,4.7,4.0
covid-19-pneumonia-19.jpg,5.0,2.0
covid-19-pneumonia-2.jpg,1.3,2.0
covid-19-pneumonia-28.png,5.7,4.0
covid-19-pneumonia-30-PA.jpg,3.0,2.0
covid-19-pneumonia-7-PA.jpg,2.3,2.3
covid-19-pneumonia-evolution-over-a-week-1-day0-PA.jpg,0.7,0.7
covid-19-pneumonia-rapidly-progressive-12-hours.jpg,7.3,3.0
covid-19-pneumonia-rapidly-progressive-3-days.jpg,8.0,3.0
covid-19-pneumonia-rapidly-progressive-admission.jpg,4.3,3.0
covid-19-rapidly-progressive-acute-respiratory-distress-syndrome-ards-admission.jpg,6.3,5.0
covid-19-rapidly-progressive-acute-respiratory-distress-syndrome-ards-day-1.jpg,7.0,4.0
covid-19-rapidly-progressive-acute-respiratory-distress-syndrome-ards-day-2.jpg,8.0,6.0
E63574A7-4188-4C8D-8D17-9D67A18A1AFA.jpeg,3.3,2.0
F2DE909F-E19C-4900-92F5-8F435B031AC6.jpeg,7.0,5.0
F4341CE7-73C9-45C6-99C8-8567A5484B63.jpeg,4.0,2.0
F63AB6CE-1968-4154-A70F-913AF154F53D.jpeg,5.7,4.0
FE9F9A5D-2830-46F9-851B-1FF4534959BE.jpeg,3.3,2.0
figure1-5e71be566aa8714a04de3386-98-left.jpeg,7.3,6.0
figure1-5e75d0940b71e1b702629659-98-right.jpeg,0.0,0.0
gr1_lrg-a.jpg,4.3,3.7
gr1_lrg-b.jpg,2.0,1.3
kjr-21-e24-g001-l-a.jpg,4.0,3.3
kjr-21-e24-g002-l-a.jpg,3.0,2.3
kjr-21-e24-g003-l-a.jpg,1.0,1.0
kjr-21-e25-g001-l-a.jpg,0.7,0.7
lancet-case2a.jpg,6.0,4.3
lancet-case2b.jpg,7.3,5.0
nCoV-radiol.2020200269.fig1-day7.jpeg,0.7,1.0
nejmc2001573_f1a.jpeg,2.0,2.0
nejmc2001573_f1b.jpeg,2.7,2.0
nejmoa2001191_f1-PA.jpeg,0.0,0.0
nejmoa2001191_f3-PA.jpeg,0.7,0.7
nejmoa2001191_f4.jpeg,1.3,1.0
nejmoa2001191_f5-PA.jpeg,2.0,2.3
radiol.2020200490.fig3.jpeg,4.3,3.3
ryct.2020200028.fig1a.jpeg,2.0,1.7
ryct.2020200034.fig2.jpeg,1.3,1.3
ryct.2020200034.fig5-day0.jpeg,3.7,3.3
ryct.2020200034.fig5-day4.jpeg,5.7,4.0
ryct.2020200034.fig5-day7.jpeg,4.3,4.0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
107 changes: 107 additions & 0 deletions predict_severity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
#!/usr/bin/env python
# coding: utf-8

import os,sys
sys.path.insert(0,"..")
from glob import glob
import matplotlib.pyplot as plt
import numpy as np
import argparse
import skimage
import pprint

import torch
import torch.nn.functional as F
import torchvision, torchvision.transforms
import skimage, skimage.filters
import torchxrayvision as xrv

parser = argparse.ArgumentParser()
parser.add_argument('img_path', type=str)
parser.add_argument('-cuda', default=False, help='', action='store_true')
parser.add_argument('-saliency_path', default=None, help='path to write the saliancy map as an image')

cfg = parser.parse_args()


img = skimage.io.imread(cfg.img_path)
img = xrv.datasets.normalize(img, 255)

# Check that images are 2D arrays
if len(img.shape) > 2:
img = img[:, :, 0]
if len(img.shape) < 2:
print("error, dimension lower than 2 for image")

# Add color channel
img = img[None, :, :]


transform = torchvision.transforms.Compose([xrv.datasets.XRayCenterCrop(),
xrv.datasets.XRayResizer(224)])

img = transform(img)


class PneumoniaSeverityNet(torch.nn.Module):
def __init__(self):
super(PneumoniaSeverityNet, self).__init__()
self.model = xrv.models.DenseNet(weights="all")
self.model.op_threshs = None
self.theta_bias_geographic_extent = torch.from_numpy(np.asarray((0.8705248236656189, 3.4137437)))
self.theta_bias_opacity = torch.from_numpy(np.asarray((0.5484423041343689, 2.5535977)))

def forward(self, x):
preds = self.model(x)
preds = preds[0,xrv.datasets.default_pathologies.index("Lung Opacity")]
geographic_extent = preds*self.theta_bias_geographic_extent[0]+self.theta_bias_geographic_extent[1]
opacity = preds*self.theta_bias_opacity[0]+self.theta_bias_opacity[1]
geographic_extent = torch.clamp(geographic_extent,0,8)
opacity = torch.clamp(opacity,0,6)
return {"geographic_extent":geographic_extent,"opacity":opacity}


model2 = PneumoniaSeverityNet()

with torch.no_grad():
img = torch.from_numpy(img).unsqueeze(0)
if cfg.cuda:
img = img.cuda()
model2 = model2.cuda()

outputs = model2(img)
print("geographic_extent (0-8):","{:1.4}".format(outputs["geographic_extent"].cpu().numpy()))
print("opacity (0-6):","{:1.4}".format(outputs["opacity"].cpu().numpy()))



def full_frame(width=None, height=None):
import matplotlib as mpl
mpl.rcParams['savefig.pad_inches'] = 0
figsize = None if width is None else (width, height)
fig = plt.figure(figsize=figsize)
ax = plt.axes([0,0,1,1], frameon=False)
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)
plt.autoscale(tight=True)

if cfg.saliency_path:
if cfg.cuda:
img = img.cuda()
model2 = model2.cuda()

img = img.requires_grad_()
outputs = model2(img)
grads = torch.autograd.grad(outputs["geographic_extent"], img)[0][0][0]
blurred = skimage.filters.gaussian(grads**2, sigma=(5, 5), truncate=3.5)

full_frame()
my_dpi = 100
fig = plt.figure(frameon=False, figsize=(224/my_dpi, 224/my_dpi), dpi=my_dpi)
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
fig.add_axes(ax)
ax.imshow(img[0][0].detach(), cmap="gray", aspect='auto')
ax.imshow(blurred, alpha=0.5);
plt.savefig(cfg.saliency_path)

5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
numpy
pandas
torch
torchvision
torchxrayvision
Loading

0 comments on commit fed90ed

Please sign in to comment.