【发布时间】:2021-07-19 12:00:59
【问题描述】:
- 125 帧
- 3 通道 (RGB)
- 每帧 128 x 128 尺寸。
- 张量中的值在
[0,1]范围内。
我想在 Google Colab 中使用 Pytorch 显示这 125 帧的视频。我该怎么做?
【问题讨论】:
标签: python video pytorch google-colaboratory tensor
[0,1] 范围内。我想在 Google Colab 中使用 Pytorch 显示这 125 帧的视频。我该怎么做?
【问题讨论】:
标签: python video pytorch google-colaboratory tensor
在 Colab 中启用内联动画的一种方法是使用 jshtml:
from matplotlib import rc
rc('animation', html='jshtml')
启用此功能后,您可以绘制动画 like so(请注意,您需要 permute 您的图像张量才能以 PIL/matplotlib 格式获取它们):
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
【讨论】:
inp = torch.rand(8,3,128,128)。究竟是什么错误/看起来有什么问题?