Guys, what's wrong in this? Pl. Check

Here- is the directory(+= folder contents)


PX1_0000- T2W.nii.gz + seg.nii.gz

PX1_0001- T2W.nii.gz+ seg.nii.gz
… PX1_0200- T2W.nii.gz+ seg.nii

Same follows for 200 patients.

def get_list_of_files(base_dir):
list_of_lists = []
for phase_type in [‘train’]:
current_directory = join(base_dir, phase_type)
patients = subfolders(current_directory, join=True)
for p in patients:
patient_directory = join(current_directory, p)
t2_file = join(patient_directory, p + “T2W.nii.gz”)
seg_file = join(patient_directory, p + “seg.nii.gz”)
this_case = [t2_file, seg_file]
assert all((isfile(i) for i in this_case)), "some file is missing for patient %s; make sure the following "
“files are there: %s” % (p, str(this_case))
print(“Found %d patients” % len(list_of_lists))
return list_of_lists


Proper formatting might be great to review problems for others.
Please explain problem briefly.

1 Like

Hi. Thanks!
My directory structure is like the above… follows for 200 folders.

I want to read in the contents of the file, but it’s not working. Where’s it going wrong?

Code snippets can be added by wrapping them into three backticks ```, which makes debugging easier.
Are you seeing an error or unexpected results when running the script?
This questions doesn’t seem to be PyTorch-specific, so you might also get a better and faster answer e.g. on StackOverflow.

1 Like