如何解决在 tensoraord 上的每个 Epoch 之后,Keras Callback 可视化训练集图像
以下代码是我用来在 tensorboard 上可视化训练图像的代码,但我只看到了一组 32 张图像。
# Visualize train images - Creates a file writer for the train directory.
logdir_train_images = r'C:Git_Source\Source\log\Train_Images\VWHF'
file_writer = tf.summary.create_file_writer(logdir_train_images)
figure = train_image_grid(train)
with file_writer.as_default():
tf.summary.image("Train data",plot_to_train_image(figure),step=0)
def plot_to_train_image(figure):
# Save the plot to a PNG in memory.
buf = io.BytesIO()
plt.savefig(buf,format='png')
# Closing the figure prevents it from being displayed directly inside
# the notebook.
plt.close(figure)
buf.seek(0)
# Convert PNG buffer to TF image
image = tf.image.decode_png(buf.getvalue(),channels=4)
# Add the batch dimension
image = tf.expand_dims(image,0)
return image
def train_image_grid(train):
imgs_train,labels_train = next(train)
label_index = np.argmax(labels_train,axis=1)
label_dict = dict((v,k) for k,v in train.class_indices.items())
figure = plt.figure(figsize=(12,12))
for i in range(len(imgs_train)):
plt.subplot(6,6,i + 1,title=label_dict[label_index[i]])
plt.xticks([])
plt.yticks([])
plt.grid(False)
plt.imshow(imgs_train[i],cmap='gray')
return figure
如何通过回调函数运行它,以便我可以看到每个时期的图像? 我对它相当陌生,任何形式的输入都将不胜感激 - 谢谢!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。