Hello, i was debugging my dataset and i observed that it invokes __getitem__ twice when batch size is set to 1. Is this normal behavior? (version torch==2.7.0.dev20250228)
def __getitem__(self, idx):
image = np.float32(load(self.img_file_locs[idx]).get_fdata())
l_targ = self.img_file_locs[idx].split('_')[-3]
target = np.float32(load(self.targets[l_targ]).get_fdata())
normalized_image = (image - np.min(image)) / (np.max(image) - np.min(image))
normalized_target = (target - np.min(target)) / (np.max(target) - np.min(target))
image = torch.from_numpy(normalized_image).unsqueeze(0)
target = torch.from_numpy(normalized_target).unsqueeze(0)
if self.debug:
print(f"image: {self.img_file_locs[idx]}")
print(f"target: {self.targets[l_targ]}")
return {'image': image, 'target': target}
Then trying it out:
rq_data = RatioDataset(tar_dir,rat_dir, use_glob=True, debug=True)
dataloader = DataLoader(rq_data, batch_size=1, num_workers=1)
q = next(iter(dataloader))
for _,v in q.items():
print(v.shape)
Which outputs this:
image: /Users/petros/Documents/PhD_outputs/IEC_Simulated_Images/10s/r10/recon_10s_r10_002_corr.nii.gz
target: /Users/petros/Documents/PhD_outputs/activity_conc_images_from_cont_label/activity_image_R10_noBlur.nii
image: /Users/petros/Documents/PhD_outputs/IEC_Simulated_Images/5s/r2/recon_5s_r2_021_corr.nii.gz
target: /Users/petros/Documents/PhD_outputs/activity_conc_images_from_cont_label/activity_image_R2_noBlur.nii
torch.Size([1, 1, 256, 256, 71])
torch.Size([1, 1, 256, 256, 71])
Is this normal behavior?