Skip to content

Instantly share code, notes, and snippets.

@McSpooder
Created July 22, 2020 18:46
Show Gist options
  • Save McSpooder/a09679fba2c577199e3cad3a5a269e1f to your computer and use it in GitHub Desktop.
Save McSpooder/a09679fba2c577199e3cad3a5a269e1f to your computer and use it in GitHub Desktop.
get item method
def __getitem__(self, idx):
if torch.is_tensor(idx):
idx = idx.tolist()
repeat = True
while(repeat):
try:
path = self.directories[idx]
im_id = get_im_id(path)
mri = get_mri(path)
clinical = get_clinical(im_id, self.clin_data)
label = get_label(path, self.labels)
sample = {'mri': mri, 'clinical':clinical, 'label':label}
if self.transform:
sample = self.transform(sample)
return sample
except Exception as e:
#print(e)
if (idx < self.len):
idx += 1
else:
idx = 0
return sample
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment