TypeError: 'module' object is not callable Tensorboard in Keras

TypeError: 'module' object is not callable Tensorboard in Keras

我正在使用策略梯度方法实现 RL 代理。我为演员定义了一个密集网络,为评论家定义了另一个密集网络。比如我的评论网络是:

state_input = Input(shape=(self.num_states,))
x = Dense(self.hidden_size, activation='tanh')(state_input)
for _ in range(self.num_layers - 1):
    x = Dense(self.hidden_size, activation='tanh')(x)

out_value = Dense(1)(x)

model = Model(inputs=[state_input], outputs=[out_value])
model.compile(optimizer=SGD(lr=self.learning_rate), loss='mse')

在训练阶段,我正在调用 tensorboard:

from keras.callbacks import TensorBoard

tensorboard = TensorBoard(log_dir="/logs/{}".format(time()), 
                          histogram_freq=1, batch_size=32, 
                          write_graph=True, write_grads=True,
                          write_images=True, embeddings_freq=0, 
                          embeddings_layer_names=None, 
                          embeddings_metadata=None, 
                          embeddings_data=None, update_freq='epoch')

critic_loss = self.critic.fit([obs, advantage, old_prediction], [action], 
                                 batch_size=self.batch_size,
                                 shuffle=True, epochs=self.epochs, verbose=False,
                                 callbacks=[tensorboard_actor])

但是我收到这个错误:

TypeError: 'module' object is not callable

TypeError: 'module' object is not callable in your case is caused by time module

我假设您将时间模块导入为

import time

并调用函数 time()

tensorboard = TensorBoard(log_dir="/logs/{}".format(time())

导入即可轻松解决:

from time import time