我試圖從Fashion MNIST資料集中隨機制作 25 張影像。
然而,當我試圖這樣做時,我的代碼只回傳一個空白畫布。
import tensorflow as tf
from matplotlib.animation import FuncAnimation
from matplotlib import pyplot as plt
import numpy as np
# these code are from the first TensorFlow official tutorial.
fashion_mnist = tf.keras.datasets.fashion_mnist
(train_images, train_labels), (test_images,
test_labels) = fashion_mnist.load_data()
class_names = ['T-shirt/top', 'Trouser', 'Pullover', 'Dress', 'Coat',
'Sandal', 'Shirt', 'Sneaker', 'Bag', 'Ankle boot']
# create a 10-inch canvas
fig = plt.figure(figsize=(10, 10))
def draw25Random():
# show 25 random images from the 60k training set
ris = np.random.randint(60000, size=25)
ris.sort()
for i in range(25):
ri = ris[i]
plt.subplot(5, 5, i 1)
plt.xticks([])
plt.yticks([])
plt.grid(False)
plt.imshow(train_images[ri], cmap=plt.cm.binary)
plt.xlabel(f'{ri} // {class_names[train_labels[ri]]}')
anim = FuncAnimation(fig,
draw25Random,
interval=1000)
(渲染 25 張影像部分很好)
有任何想法嗎?
uj5u.com熱心網友回復:
對于這種
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/436221.html
標籤:Python matplotlib 动画 可视化 子情节
下一篇:如何為精靈設定影片?
