在 TensorFlow 中还原检查点时出现错误

3
def test_neural_network():
    prediction = neural_network_model(x)
    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        for epoch in range(hm_epochs):
            saver.restore(sess, './model.ckpt')
        # more code here

这是我正在处理的代码示例。 我已经将 model.ckpt 文件保存在与我的文件相同的目录中。
然而,当我运行代码时,出现错误提示:
InvalidArgumentError (see above for traceback): Expected to restore a tensor of type float, got a tensor of type int32 instead: tensor_name = Variable
 [[Node: save/RestoreV2 = RestoreV2[dtypes=[DT_FLOAT], _device="/job:localhost/replica:0/task:0/cpu:0"](_recv_save/Const_0, save/RestoreV2/tensor_names, save/RestoreV2/shape_and_slices)]]
1个回答

0

看起来你定义的模型与保存的模型有所不同。尝试使用saver = tf.train.import_meta_graph('your_model_name.meta')而不是在neural_network_model()中手动构建图形。


我使用了saver = tf.train.Saver()。现在运行train_neural_network时出现错误,提示ValueError: No gradients provided for any variable, check your graph for ops that do not support gradients, between variables. - humble

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接