Chris Oswald
commited on
Commit
·
c4ed090
1
Parent(s):
af71e33
converted data types
Browse files
SPIDER.py
CHANGED
|
@@ -15,6 +15,7 @@
|
|
| 15 |
|
| 16 |
# Import packages
|
| 17 |
import csv
|
|
|
|
| 18 |
import os
|
| 19 |
from typing import Dict, List, Mapping, Optional, Sequence, Set, Tuple, Union
|
| 20 |
|
|
@@ -64,7 +65,9 @@ MAX_IVD = 9
|
|
| 64 |
DEFAULT_SCAN_TYPES = ['t1', 't2', 't2_SPACE']
|
| 65 |
DEFAULT_RESIZE = (512, 512, 30)
|
| 66 |
DEMO_SUBSET_N = 10
|
| 67 |
-
|
|
|
|
|
|
|
| 68 |
_CITATION = """\
|
| 69 |
@misc{vandergraaf2023lumbar,
|
| 70 |
title={Lumbar spine segmentation in MR images: a dataset and a public benchmark},
|
|
@@ -197,46 +200,47 @@ class SPIDER(datasets.GeneratorBasedBuilder):
|
|
| 197 |
"mask": datasets.Array3D(shape=self.config.resize_shape, dtype='uint8'),
|
| 198 |
"image_path": datasets.Value("string"),
|
| 199 |
"mask_path": datasets.Value("string"),
|
| 200 |
-
"metadata": {
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
|
|
|
| 240 |
"rad_gradings": {
|
| 241 |
"IVD label": datasets.Sequence(datasets.Value("string")),
|
| 242 |
"Modic": datasets.Sequence(datasets.Value("string")),
|
|
@@ -356,7 +360,7 @@ class SPIDER(datasets.GeneratorBasedBuilder):
|
|
| 356 |
# Import patient/scanner data and radiological gradings data
|
| 357 |
overview_data = import_csv_data(paths_dict['overview'])
|
| 358 |
grades_data = import_csv_data(paths_dict['gradings'])
|
| 359 |
-
|
| 360 |
# Convert overview data list of dicts to dict of dicts
|
| 361 |
exclude_vars = ['new_file_name', 'subset'] # Original data only lists train and validate
|
| 362 |
overview_dict = {}
|
|
@@ -367,6 +371,22 @@ class SPIDER(datasets.GeneratorBasedBuilder):
|
|
| 367 |
}
|
| 368 |
overview_dict[key]['OrigSubset'] = item['subset'] # Change name to original subset
|
| 369 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 370 |
# Merge patient records for radiological gradings data
|
| 371 |
grades_dict = {}
|
| 372 |
for patient_id in patient_ids:
|
|
|
|
| 15 |
|
| 16 |
# Import packages
|
| 17 |
import csv
|
| 18 |
+
import json
|
| 19 |
import os
|
| 20 |
from typing import Dict, List, Mapping, Optional, Sequence, Set, Tuple, Union
|
| 21 |
|
|
|
|
| 65 |
DEFAULT_SCAN_TYPES = ['t1', 't2', 't2_SPACE']
|
| 66 |
DEFAULT_RESIZE = (512, 512, 30)
|
| 67 |
DEMO_SUBSET_N = 10
|
| 68 |
+
with open("TextFiles/var_types.json", "r") as io:
|
| 69 |
+
VAR_TYPES = json.load(io)
|
| 70 |
+
|
| 71 |
_CITATION = """\
|
| 72 |
@misc{vandergraaf2023lumbar,
|
| 73 |
title={Lumbar spine segmentation in MR images: a dataset and a public benchmark},
|
|
|
|
| 200 |
"mask": datasets.Array3D(shape=self.config.resize_shape, dtype='uint8'),
|
| 201 |
"image_path": datasets.Value("string"),
|
| 202 |
"mask_path": datasets.Value("string"),
|
| 203 |
+
"metadata": {k:datasets.Value(v) for k,v in VAR_TYPES['metadata'].items()},
|
| 204 |
+
# {
|
| 205 |
+
# "num_vertebrae": datasets.Value("int16"),
|
| 206 |
+
# "num_discs": datasets.Value("int16"),
|
| 207 |
+
# "sex": datasets.Value("string"),
|
| 208 |
+
# "birth_date": datasets.Value("string"),
|
| 209 |
+
# "AngioFlag": datasets.Value("string"),
|
| 210 |
+
# "BodyPartExamined": datasets.Value("string"),
|
| 211 |
+
# "DeviceSerialNumber": datasets.Value("string"),
|
| 212 |
+
# "EchoNumbers": datasets.Value("float32"),
|
| 213 |
+
# "EchoTime": datasets.Value("float32"),
|
| 214 |
+
# "EchoTrainLength": datasets.Value("float32"),
|
| 215 |
+
# "FlipAngle": datasets.Value("float32"),
|
| 216 |
+
# "ImagedNucleus": datasets.Value("string"),
|
| 217 |
+
# "ImagingFrequency": datasets.Value("float32"),
|
| 218 |
+
# "InPlanePhaseEncodingDirection": datasets.Value("string"),
|
| 219 |
+
# "MRAcquisitionType": datasets.Value("string"),
|
| 220 |
+
# "MagneticFieldStrength": datasets.Value("float32"),
|
| 221 |
+
# "Manufacturer": datasets.Value("string"),
|
| 222 |
+
# "ManufacturerModelName": datasets.Value("string"),
|
| 223 |
+
# "NumberOfPhaseEncodingSteps": datasets.Value("int32"),
|
| 224 |
+
# "PercentPhaseFieldOfView": datasets.Value("float64"),
|
| 225 |
+
# "PercentSampling": datasets.Value("float64"),
|
| 226 |
+
# "PhotometricInterpretation": datasets.Value("string"),
|
| 227 |
+
# "PixelBandwidth": datasets.Value("int32"),
|
| 228 |
+
# "PixelSpacing": datasets.Sequence(datasets.Value("float32")),
|
| 229 |
+
# "RepetitionTime": datasets.Value("float64"),
|
| 230 |
+
# "SAR": datasets.Value("float64"),
|
| 231 |
+
# "SamplesPerPixel": datasets.Value("int32"),
|
| 232 |
+
# "ScanningSequence": datasets.Value("string"),
|
| 233 |
+
# "SequenceName": datasets.Value("string"),
|
| 234 |
+
# "SeriesDescription": datasets.Value("string"),
|
| 235 |
+
# "SliceThickness": datasets.Value("float32"),
|
| 236 |
+
# "SoftwareVersions": datasets.Sequence(datasets.Value("string")),
|
| 237 |
+
# "SpacingBetweenSlices": datasets.Value("float32"),
|
| 238 |
+
# "SpecificCharacterSet": datasets.Value("string"),
|
| 239 |
+
# "TransmitCoilName": datasets.Value("string"),
|
| 240 |
+
# "WindowCenter": datasets.Value("float32"),
|
| 241 |
+
# "WindowWidth": datasets.Value("float32"),
|
| 242 |
+
# "OrigSubset":datasets.Value("string"),
|
| 243 |
+
# },
|
| 244 |
"rad_gradings": {
|
| 245 |
"IVD label": datasets.Sequence(datasets.Value("string")),
|
| 246 |
"Modic": datasets.Sequence(datasets.Value("string")),
|
|
|
|
| 360 |
# Import patient/scanner data and radiological gradings data
|
| 361 |
overview_data = import_csv_data(paths_dict['overview'])
|
| 362 |
grades_data = import_csv_data(paths_dict['gradings'])
|
| 363 |
+
|
| 364 |
# Convert overview data list of dicts to dict of dicts
|
| 365 |
exclude_vars = ['new_file_name', 'subset'] # Original data only lists train and validate
|
| 366 |
overview_dict = {}
|
|
|
|
| 371 |
}
|
| 372 |
overview_dict[key]['OrigSubset'] = item['subset'] # Change name to original subset
|
| 373 |
|
| 374 |
+
# Convert overview data types
|
| 375 |
+
cast_overview_dict = {}
|
| 376 |
+
for scan_id, scan_metadata in overview_dict.items():
|
| 377 |
+
cast_dict = {}
|
| 378 |
+
for key, value in scan_metadata.items():
|
| 379 |
+
if key in VAR_TYPES['metadata']:
|
| 380 |
+
new_type = VAR_TYPES['metadata'][key]
|
| 381 |
+
if new_type != "string":
|
| 382 |
+
cast_dict[key] = eval(f'np.{new_type}({value})')
|
| 383 |
+
else:
|
| 384 |
+
cast_dict[key] = str(value)
|
| 385 |
+
else:
|
| 386 |
+
cast_dict[key] = value
|
| 387 |
+
cast_overview_dict[scan_id] = cast_dict
|
| 388 |
+
overview_dict = cast_overview_dict
|
| 389 |
+
|
| 390 |
# Merge patient records for radiological gradings data
|
| 391 |
grades_dict = {}
|
| 392 |
for patient_id in patient_ids:
|