问题描述
我一直无法在张量板上绘制学习率,因为我按如下方式使用ReduceLROnPlateau:
tensorboard_callback = tf.keras.callbacks.TensorBoard(log_dir=results_path,histogram_freq=1)
reduce_lr = ReduceLROnPlateau(monitor='loss',factor=0.5,verbose=1,patience=100,min_lr=0.000001)
callbacks = [tensorboard_callback,reduce_lr]
# Compile VAE
vae.compile(optimizer='adam',loss=kl_reconstruction_loss,metrics=["mse",metric_KL,binary_crossentropy])
# Train autoencoder
history = vae.fit(x_train,x_train,epochs = no_epochs,batch_size = batch_size,validation_data=(x_test,x_test,),callbacks=callbacks)
之后,我运行它以将自定义指标绘制到张量板日志:
for epoch in range(len(history.history['mse'])):
with train_summary_writer.as_default():
tf.summary.scalar('metric_KL',history.history['metric_KL'][epoch],step=epoch)
使用该设置。如何在不编写自己的自定义ReduceLROnPlateau的情况下绘制学习率? 谢谢
解决方法
推荐的方法是覆盖UITextView
回调。
您可以在此处看到如何执行此操作:Keras: how to output learning rate onto tensorboard。
您只需要使用导入TensorBoard
而不是简单的tensorflow.keras
来修改代码即可。