Skip to content

Instantly share code, notes, and snippets.

@InEase
Created July 6, 2022 00:48
Show Gist options
  • Save InEase/5c70567b3b8cd142acb7bcaaecec49d9 to your computer and use it in GitHub Desktop.
Save InEase/5c70567b3b8cd142acb7bcaaecec49d9 to your computer and use it in GitHub Desktop.
Show picture examples of DataLoader/Dataset images with masks
# example of train images with masks
ds = HuBMAPDataset(transforms=augmentations)
dl = DataLoader(ds, batch_size=bs, shuffle=False, num_workers=NUM_WORKERS)
imgs, masks = next(iter(dl))
plt.figure(figsize=(16, 16))
for i, (img, mask) in enumerate(zip(imgs, masks)):
img = ((img.permute(1, 2, 0) * std + mean) * 255.0).numpy().astype(np.uint8)
plt.subplot(8, 8, i + 1)
plt.imshow(img, vmin=0, vmax=255)
plt.imshow(mask.squeeze().numpy(), alpha=0.2)
plt.axis('off')
plt.subplots_adjust(wspace=None, hspace=None)
del ds, dl, imgs, masks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment