-
-
Notifications
You must be signed in to change notification settings - Fork 222
/
dataset_utils.py
144 lines (114 loc) · 5 KB
/
dataset_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import torchvision, torchvision.transforms
import sys, os
sys.path.insert(0,"../torchxrayvision/")
import torchxrayvision as xrv
import matplotlib.pyplot as plt
import torch
from torch.nn import functional as F
import glob
import numpy as np
import skimage, skimage.filters
import captum, captum.attr
import torch, torch.nn
import pickle
import pandas as pd
def get_data(dataset_str, masks=False, unique_patients=False,
transform=None, data_aug=None, merge=True, views = ["PA","AP"],
pathologies=None):
dataset_dir = "/home/groups/akshaysc/joecohen/"
datasets = []
if "covid" in dataset_str:
dataset = xrv.datasets.COVID19_Dataset(
imgpath=dataset_dir + "/covid-chestxray-dataset/images",
csvpath=dataset_dir + "/covid-chestxray-dataset/metadata.csv",
transform=transform, data_aug=data_aug, semantic_masks=masks,
views=views)
datasets.append(dataset)
if "pc" in dataset_str:
dataset = xrv.datasets.PC_Dataset(
imgpath=dataset_dir + "/images-512-PC",
transform=transform, data_aug=data_aug,
unique_patients=unique_patients,
views=views)
datasets.append(dataset)
if "rsna" in dataset_str:
dataset = xrv.datasets.RSNA_Pneumonia_Dataset(
imgpath=dataset_dir + "/kaggle-pneumonia-jpg/stage_2_train_images_jpg",
transform=transform, data_aug=data_aug,
unique_patients=unique_patients, pathology_masks=masks,
views=views)
datasets.append(dataset)
if "nih" in dataset_str:
dataset = xrv.datasets.NIH_Dataset(
imgpath=dataset_dir + "/images-512-NIH",
transform=transform, data_aug=data_aug,
unique_patients=unique_patients, pathology_masks=masks,
views=views)
datasets.append(dataset)
if "siim" in dataset_str:
dataset = xrv.datasets.SIIM_Pneumothorax_Dataset(
imgpath=dataset_dir + "SIIM_TRAIN_TEST/dicom-images-train/",
csvpath=dataset_dir + "SIIM_TRAIN_TEST/train-rle.csv",
transform=transform, data_aug=data_aug,
unique_patients=unique_patients, pathology_masks=masks)
datasets.append(dataset)
if "chex" in dataset_str:
dataset = xrv.datasets.CheX_Dataset(
imgpath=dataset_dir + "/CheXpert-v1.0-small",
csvpath=dataset_dir + "/CheXpert-v1.0-small/train.csv",
transform=transform, data_aug=data_aug,
unique_patients=False,
views=views)
datasets.append(dataset)
if "google" in dataset_str:
dataset = xrv.datasets.NIH_Google_Dataset(
imgpath=dataset_dir + "/images-512-NIH",
transform=transform, data_aug=data_aug,
views=views)
datasets.append(dataset)
if "mimic_ch" in dataset_str:
dataset = xrv.datasets.MIMIC_Dataset(
imgpath="/scratch/users/joecohen/data/MIMICCXR-2.0/files/",
csvpath=dataset_dir + "/MIMICCXR-2.0/mimic-cxr-2.0.0-chexpert.csv.gz",
metacsvpath=dataset_dir + "/MIMICCXR-2.0/mimic-cxr-2.0.0-metadata.csv.gz",
transform=transform, data_aug=data_aug,
unique_patients=unique_patients,
views=views)
datasets.append(dataset)
if "openi" in dataset_str:
dataset = xrv.datasets.Openi_Dataset(
imgpath=dataset_dir + "/OpenI/images/",
transform=transform, data_aug=data_aug,
views=views)
datasets.append(dataset)
if "vin" in dataset_str:
dataset = xrv.datasets.VinBrain_Dataset(
imgpath=dataset_dir + "vinbigdata-chest-xray-abnormalities-detection/train",
csvpath=dataset_dir + "vinbigdata-chest-xray-abnormalities-detection/train.csv",
pathology_masks=masks,
transform=transform, data_aug=data_aug,
views=views)
datasets.append(dataset)
if "objectcxr" in dataset_str:
dataset = xrv.datasets.ObjectCXR_Dataset(imgzippath=dataset_dir + "/object-CXR/train.zip",
csvpath=dataset_dir + "/object-CXR/train.csv",
pathology_masks=masks,
transform=transform,
data_aug=data_aug)
datasets.append(dataset)
if not pathologies is None:
for d in datasets:
xrv.datasets.relabel_dataset(pathologies, d)
if merge:
newlabels = set()
for d in datasets:
newlabels = newlabels.union(d.pathologies)
# if "Support Devices" in newlabels:
# newlabels.remove("Support Devices")
print(list(newlabels))
for d in datasets:
xrv.datasets.relabel_dataset(list(newlabels), d)
dmerge = xrv.datasets.Merge_Dataset(datasets)
return dmerge
else:
return datasets