Skip to content

Instantly share code, notes, and snippets.

@fepegar
Last active November 14, 2021 11:13
Show Gist options
  • Save fepegar/a015944da46d4e147a4362e63ec51019 to your computer and use it in GitHub Desktop.
Save fepegar/a015944da46d4e147a4362e63ec51019 to your computer and use it in GitHub Desktop.
import torch
import torchio as tio
from einops import rearrange
rows = 16
cols = 28
dataset = tio.datasets.OrganMNIST3D('train')
batch_size = rows * cols
loader = torch.utils.data.DataLoader(dataset, batch_size=batch_size, shuffle=True)
batch = tio.utils.get_first_item(loader)
tensor = batch['image'][tio.DATA]
pattern = '(b1 b2) c x y z -> c x (b1 y) (b2 z)'
tensor = rearrange(tensor, pattern, b1=cols, b2=rows)
image = tio.ScalarImage(tensor=tensor)
image.to_gif(0, 2, f'/tmp/{dataset.__class__.__name__}.gif')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment