I have a tensor of shape
(125, 3, 128, 128)
:
- 125 frames
- 3 channels (RGB)
- each frame 128 x 128 size.
- values in the tensor are in the range
[0,1]
.
I want to display the video of these 125 frames, using Pytorch in Google Colab. How can I do that?
I have a tensor of shape
(125, 3, 128, 128)
:
[0,1]
.I want to display the video of these 125 frames, using Pytorch in Google Colab. How can I do that?
One way to enable inline animations in Colab is using jshtml
:
from matplotlib import rc
rc('animation', html='jshtml')
With this enabled, you can then plot your animation like so (note you will need to permute your image tensors to get them in PIL/matplotlib format):
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig, ax = plt.subplots()
imgs = torch.rand(10,3,128,128)
imgs = imgs.permute(0,2,3,1) # Permuting to (Bx)HxWxC format
frames = [[ax.imshow(imgs[i])] for i in range(len(imgs))]
ani = animation.ArtistAnimation(fig, frames)
ani