需要帮助
我正在使用“moving_mnist”数据集进行工作。使用tfds.load(“moving_mnist”)
加载此数据,然后使用tfds.as_numpy()
将其转换为数组,它将返回形状为(20,64,64,1)的图像序列数组,其中20是帧数。现在我想要的是在我的jupyter笔记本中将这些数组显示为GIF,请参见下面我尝试过的代码,但它只会为最后一帧生成简单的图像。
import tensorflow_datasets as tfds
ds, ds_info = tfds.load("moving_mnist", with_info = True,split="test")
num_examples = 3
examples = list(dataset_utils.as_numpy(ds.take(num_examples)))
fig = plt.figure(figsize=(3*3, 3*3))
fig.subplots_adjust(hspace=1/3, wspace=1/3)
for i, ex in enumerate(examples):
video = ex["image-sequence"]
frame,height, width, c = video.shape
if c == 1:
video = video.reshape(video.shape[:3])
for i in range(0,frame):
ax.imshow(video[i,:,:], animated=True)
这里是我得到的结果,但我想要它作为GIF格式