本文介绍了在运行此代码以训练 Deep Q 网络时,我收到“ModifiedTensorBoard"对象没有属性“_write_logs"的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在运行以下代码:
class ModifiedTensorBoard(TensorBoard):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.step = 1
self.writer = tf.summary.create_file_writer(self.log_dir)
def set_model(self, model):
pass
def on_epoch_end(self, epoch, logs=None):
self.update_stats(**logs)
def on_batch_end(self, batch, logs=None):
pass
def on_train_end(self, _):
pass
def update_stats(self, **stats):
self._write_logs(stats, self.step)
得到错误:
232 def update_stats(self, **stats):
--> 233 self._write_logs(stats, self.step)
234
235
AttributeError: 'ModifiedTensorBoard' object has no attribute '_write_logs'
有人可以建议如何克服这个问题吗?谢谢.
Can someone suggest how to overcome this problem? Thanks.
推荐答案
创建一个_write_logs"功能如下:
create a "_write_logs" function as following:
def update_stats(self, **stats):
self._write_logs(stats, self.step)
def _write_logs(self, logs, index):
with self.writer.as_default():
for name, value in logs.items():
tf.summary.scalar(name, value, step=index)
self.step += 1
self.writer.flush()
这篇关于在运行此代码以训练 Deep Q 网络时,我收到“ModifiedTensorBoard"对象没有属性“_write_logs"的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!