Created
July 22, 2020 18:46
-
-
Save McSpooder/a09679fba2c577199e3cad3a5a269e1f to your computer and use it in GitHub Desktop.
get item method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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