当我尝试将keras NN模型的结果放入tensorborad时,出现了一些错误。
我将tf.summary代码放在回调函数上。但这不起作用。
Class Showresult(Callback):
def on_epoch_end(self,epoch,logs={}):
k,R=self.model.get_layer('sauvola_layer_22').get_weights()
test = Model(model.inputs, model.get_layer('difference').output)
X, Y = valid_datagen[0]
Z = test.predict(X)
pyplot.subplot(131)
pyplot.imshow(X[0,...,0])
pyplot.subplot(132)
pyplot.imshow(Y[0,...,0])
pyplot.subplot(133)
pyplot.imshow(Z[0,...,0])
k = k.ravel()[0]
R = R.ravel()[0]
print("Epoch{}: Sauvola k={:.2f},R={:.2f}".format(epoch,k,R))
sess = tf.Session()
with tf.name_scope('summaries'):
tf.summary.scalar('k_value', k)
tf.summary.scalar('R_value', R)
tf.summary.scalar('outputs', Z)
merged = tf.summary.merge_all()
print(merged)
writer = tf.summary.FileWriter('./log/'+'otsu-Rescale- B32',sess.graph)
summary = sess.run(merged)
writer.add_summary(summary, epoch)
writer.close()
sess.close()