【发布时间】:2019-01-09 04:21:12
【问题描述】:
我正在尝试找到一种方法来查找和修复我的 TF 代码中的错误。下面代码的sn-p成功训练模型,但调用最后一行(model.evaluate(input_fn))时产生如下错误:
InvalidArgumentError: Restoring from checkpoint failed. This is most likely due to a mismatch between the current graph and the graph from the checkpoint. Please ensure that you have not altered the graph expected based on the checkpoint. Original error:
/var/folders/kx/y9syv3f91b1c6tzt3fgzc7jm0000gn/T/tmp_r6c94ni/model.ckpt-667.data-00000-of-00001; Invalid argument
[[node save/RestoreV2 (defined at ../text_to_topic/train/nn/nn_tf.py:266) = RestoreV2[dtypes=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_INT64], _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_save/Const_0_0, save/RestoreV2/tensor_names, save/RestoreV2/shape_and_slices)]]
Caused by op 'save/RestoreV2', defined at:
File "/Users/foo/miniconda3/envs/tt/lib/python3.6/runpy.py", line 193, in _run_module_as_main
完全相同的代码在用于 MNIST 数据集时有效,但在用于我自己的数据集时无效。我该如何调试这个或可能是什么原因。从检查点恢复模型后,图表似乎不匹配,但我不确定如何继续解决这个问题。我试过 TF 版本 1.11 和 1.13
model = tf.estimator.Estimator(get_nn_model_fn(num_classes))
# Define the input function for training
input_fn = tf.estimator.inputs.numpy_input_fn(
x=X_train, y=y_train,
batch_size=batch_size,
num_epochs=None, shuffle=True)
# Train the Model
model.train(input_fn, steps=num_steps)
# Evaluate the Model
# Define the input function for evaluating
input_fn = tf.estimator.inputs.numpy_input_fn(
x=X_test, y=y_test,
batch_size=batch_size, shuffle=False)
# Use the Estimator 'evaluate' method
e = model.evaluate(input_fn)
【问题讨论】:
标签: tensorflow tensorflow-estimator