Einstellung
commited on
Commit
·
f972ca0
1
Parent(s):
ddbdc5f
First version of the CXR_Reports dataset
Browse files- CXR_Reports.py +50 -0
CXR_Reports.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import tensorflow as tf
|
2 |
+
import datasets
|
3 |
+
|
4 |
+
|
5 |
+
_DESCRIPTION = (
|
6 |
+
"This dataset consists 90k images of Chest-X-Ray from the Mimic-CXR dataset."
|
7 |
+
"For each image, we have a consise report obtain from de PRO-CXR dataset"
|
8 |
+
"All images have a size of 512x512 pixels."
|
9 |
+
)
|
10 |
+
|
11 |
+
|
12 |
+
_BASE_URL = "https://drive.google.com/file/d/1u27GCgIIRqDz8a5-VTcMJ1pEFQbGv_QB/view?usp=sharing"
|
13 |
+
|
14 |
+
FEATURE_DESCRIPTION_TFRECORD = {
|
15 |
+
'report': tf.io.FixedLenFeature([], tf.string),
|
16 |
+
'image': tf.io.FixedLenFeature([], tf.string),
|
17 |
+
}
|
18 |
+
|
19 |
+
|
20 |
+
class ReportsCXR(datasets.GeneratorBasedBuilder):
|
21 |
+
def _info(self):
|
22 |
+
return datasets.DatasetInfo(
|
23 |
+
description = _DESCRIPTION,
|
24 |
+
features = datasets.Features(
|
25 |
+
'image': datasets.Image(),
|
26 |
+
'report': datasets.Value(dtype='string')
|
27 |
+
)
|
28 |
+
)
|
29 |
+
def _get_drive_url(self, url):
|
30 |
+
base_url = 'https://drive.google.com/uc?id='
|
31 |
+
split_url = url.split('/')
|
32 |
+
return base_url + split_url[5]
|
33 |
+
|
34 |
+
def _split_generators(self, dl_manager):
|
35 |
+
archive_path = dl_manager.download(self._get_drive_url(_BASE_URL))
|
36 |
+
return [
|
37 |
+
datasets.SplitGenerator(name='full', gen_kwargs={'filepath': dl_manager.iter_archive(archive_path)})
|
38 |
+
]
|
39 |
+
|
40 |
+
def _parse_image_function(example_proto):
|
41 |
+
# Parse the input tf.train.Example proto using the dictionary above.
|
42 |
+
return tf.io.parse_single_example(example_proto, FEATURE_DESCRIPTION_TFRECORD)
|
43 |
+
|
44 |
+
def _generate_examples(self, filepath):
|
45 |
+
raw_image_dataset = tf.data.TFRecordDataset(filepath)
|
46 |
+
parsed_image_dataset = raw_image_dataset.map(self._parse_image_function)
|
47 |
+
for image_features in parsed_image_dataset:
|
48 |
+
image_raw = image_features['image'].numpy()
|
49 |
+
yield {'image': image_raw, 'report': image_features['report']}
|
50 |
+
|