简体   繁体   中英

Keras - plot values to tensorboard

I have the following code (using 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]))

It plot's the loss and the accuracy to tensorboard.

But i want to plot the np.average(exploitabilty) as well to tensorboard - how does it work? Is there any possibility to pass it as a metric or something similar?

You can add custom metrics to your model when you compile it, eg:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM