Chris Oswald commited on
Commit
4097551
·
1 Parent(s): 0281887

padded radiological gradings

Browse files
Files changed (1) hide show
  1. SPIDER.py +23 -2
SPIDER.py CHANGED
@@ -418,7 +418,14 @@ class SPIDER(datasets.GeneratorBasedBuilder):
418
  ]
419
  if patient_grades:
420
  grades_dict[str(patient_id)] = patient_grades
421
-
 
 
 
 
 
 
 
422
  # Import image and mask data
423
  image_files = [
424
  file for file in os.listdir(os.path.join(paths_dict['images'], 'images'))
@@ -496,7 +503,21 @@ class SPIDER(datasets.GeneratorBasedBuilder):
496
  if k not in ['Patient', 'IVD label']
497
  }
498
  patient_grades_dict[key] = value
499
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
500
  # Prepare example return dict
501
  return_dict = {'patient_id':patient_id, 'scan_type':scan_type}
502
  # if raw_image:
 
418
  ]
419
  if patient_grades:
420
  grades_dict[str(patient_id)] = patient_grades
421
+
422
+ # Determine maximum number of radiological gradings per patient
423
+ max_ivd = 0
424
+ for temp_dict_1 in grades_dict.values():
425
+ for temp_dict_2 in temp_dict_1:
426
+ if int(temp_dict_2['IVD label']) > max_ivd:
427
+ max_ivd = int(temp_dict_2['IVD label'])
428
+
429
  # Import image and mask data
430
  image_files = [
431
  file for file in os.listdir(os.path.join(paths_dict['images'], 'images'))
 
503
  if k not in ['Patient', 'IVD label']
504
  }
505
  patient_grades_dict[key] = value
506
+
507
+ # Pad patient radiological gradings so that data for all patients
508
+ # have the same dimensions
509
+ for i in range(len(patient_grades_dict) + 1, max_ivd + 1):
510
+ patient_grades_dict[f'IVD{i}'] = {
511
+ "Modic": "",
512
+ "UP endplate": "",
513
+ "LOW endplate": "",
514
+ "Spondylolisthesis": "",
515
+ "Disc herniation": "",
516
+ "Disc narrowing": "",
517
+ "Disc bulging": "",
518
+ "Pfirrman grade": "",
519
+ }
520
+
521
  # Prepare example return dict
522
  return_dict = {'patient_id':patient_id, 'scan_type':scan_type}
523
  # if raw_image: