Keras - 将值绘制到 tensorboard

Keras - plot values to tensorboard

我有以下代码(使用 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) 绘制到 tensorboard - 它是如何工作的?是否有可能将其作为指标或类似的东西传递?

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

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])