我用Keras创建了一个神经模型,并希望通过用于Keras模型的Tensorflow Estimator API进行训练。
我还想简单地用LoggingTensorHook记录损失值。但是我收到以下错误:
ValueError: Passed Tensor("loss/mul:0", shape=(), dtype=float32) should have graph attribute that is equal to current graph <tensorflow.python.framework.ops.Graph object at 0x11fca7358>.
我对发生的事情有一个大概的了解。 (估算者创建一个新图形或其他图形),但我自己无法解决此问题。
现在输入一些代码:
model = create_keras_model(shapes)
adam = tf.keras.optimizers.Adam(lr=conf.lr)
model.compile(loss='categorical_crossentropy',
optimizer=adam, metrics=['acc'])
estimator = tf.keras.estimator.model_to_estimator(
keras_model=model, model_dir=model_dir,config=run_config)
### I want to log this tensor
loss_to_log = model.total_loss
log_hook = tf.train.LoggingTensorHook(
{'loss': loss_to_log}, every_n_iter=10, at_end=True)
train_spec = tf.estimator.TrainSpec(
input_fn=...,
max_steps=..., hooks=[log_hook])
tf.estimator.train_and_evaluate(estimator, train_spec, ...)
答案 0 :(得分:-1)
尝试添加代码:
ErrorDocument 404 /yourCustom404Template.html
并修改您的代码
import tensorflow as tf
tf.logging.set_verbosity(tf.logging.INFO)
到
{'loss': loss_to_log}