Skip to content

Instantly share code, notes, and snippets.

@AlessandroMondin
Last active July 22, 2022 10:09
Show Gist options
  • Save AlessandroMondin/f2edcfcff0802ba1588a721a3e4152fc to your computer and use it in GitHub Desktop.
Save AlessandroMondin/f2edcfcff0802ba1588a721a3e4152fc to your computer and use it in GitHub Desktop.
def __getitem__(self, idx):
img = np.array(Image.open(os.path.join(self.db_root_dir, self.img_list[idx])).convert("RGB"), dtype=np.float32)
gt = np.array(Image.open(os.path.join(self.db_root_dir, self.labels[idx])).convert("L"), dtype=np.float32)
gt = ((gt/np.max([gt.max(), 1e-8])) > 0.5).astype(np.float32)
#gt = gt.astype(np.bool).astype(np.float32)
if self.transform is not None:
augmentations = self.transform(image=img, mask=gt)
img = augmentations["image"]
gt = augmentations["mask"]
if self.pad_mirroring:
img = Pad(padding=self.pad_mirroring, padding_mode="reflect")(img)
return img, gt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment