我正在尝试将验证集图像添加到Keras的TensorBoard回调中。以下代码有效,甚至为我提供了每个批处理步骤的滑块。
但是,批处理步骤将附加到标签,因此最终将每个图像显示为单独的标签(例如predictions_1
,predictions_2
,predictions_3
)。
有什么办法可以防止标签被附加?
class TensorBoardWithImages(K.callbacks.TensorBoard):
def __init__(self, **kwargs):
super(TensorBoardWithImages, self).__init__(**kwargs)
def on_batch_end(self, batch, logs=None):
logs = logs or {}
val_data = self.validation_data
a=np.random.randint(0, val_data[0].shape[0], 10)
tf.summary.image(name="predictions", tensor=val_data[0][a],
max_outputs=3)
summary_op = tf.summary.merge_all()
self.writer.add_summary(summary_op.eval(session=self.sess), batch)
super(TensorBoardWithImages, self).on_batch_end(batch, logs)