【问题标题】:Keras - plot values to tensorboardKeras - 将值绘制到张量板上
【发布时间】:2018-10-19 20:03:07
【问题描述】:

我有以下代码(使用 Keras):

self.tensorboard = TensorBoard(log_dir='./logs', histogram_freq=0,
                                   write_graph=False, write_images=True)

input_ = Input(shape=self.s_dim, name='input')
hidden = Dense(self.n_hidden, activation='relu')(input_)
out = Dense(3, activation='softmax')(hidden)

model = Model(inputs=input_, outputs=out, name="br-model")
model.compile(loss='mean_squared_error', optimizer=SGD(lr=0.005), metrics=['accuracy'])

# Some stuff in-between
model.fit(batch, target, epochs=2, verbose=0, callbacks=[self.tensorboard])

for k in batch:
    exploitability.append(np.max(model.predict(batch[k]))

它绘制了张量板的损失和准确性。

但我也想将np.average(exploitabilty) 绘制到张量板上——它是如何工作的?是否有可能将其作为指标或类似的东西传递?

【问题讨论】:

    标签: python tensorflow machine-learning keras tensorboard


    【解决方案1】:

    您可以在编译模型时将自定义指标添加到模型中,例如:

    def custom_metric(y_true, y_pred):
        max = K.max(y_pred)
        return max
    
    model.compile(loss='mean_squared_error', optimizer=SGD(lr=0.005), 
                  metrics=['accuracy', custom_metric])
    

    【讨论】:

    • y_truey_pred 定义为?我将状态及其目标值传递给 fit 函数(它是 DQN 算法)。所以y_true = 状态和y_pred = 目标值?因为我已按照建议实施,它不适合 np.average(exploitability) 输出。
    • Keras 将为每个训练批次调用为y_true 提供模型目标的指标,并将其输出/预测调用为y_pred(不是为整个训练数据集调用一次)。这另一个thread 可能会澄清结果差异。
    猜你喜欢
    • 2018-08-14
    • 1970-01-01
    • 2017-07-11
    • 2017-06-20
    • 1970-01-01
    • 2019-03-19
    • 1970-01-01
    • 2018-03-25
    • 1970-01-01
    相关资源
    最近更新 更多