我使用张量流中的cnn创建了一个二元分类器,并为它计算了所有权重 . 现在它可以进行培训和测试 . 我需要编写一个预测函数,该函数应该采用计算出的参数和单个图像,并且应该给出预测输出 .

我写了以下函数来做同样的事情,但在运行它时会给出错误:

Tensor("W1:0", shape=(4, 4, 3, 8), dtype=float32_ref) must be from the same graph as Tensor("Placeholder:0", shape=(?, 64, 64, 3), dtype=float32).

def inferce_prediction(image_data, parameters):
  #X, Y = create_placeholders(n_H0, n_W0, n_C0, n_y)
  Z3 = forward_propagation(X, parameters)
  with tf.Session() as sess:
    predict_op = tf.argmax(Z3, 1)
    correct_prediction = tf.equal(predict_op, tf.argmax(Y, 1))
    accuracy = tf.reduce_mean(tf.cast(correct_prediction, "float")).eval({X: image_data})
    #test_accuracy = accuracy.eval({X: X_test, Y: Y_test})

  print ("test accuracy: ", test_accuracy)
  return parameters

您可以使用以下链接访问完整代码:https://github.com/NeonGod314/Keller-asl-classifier-in-core keller_model_for_sign_classification.ipynb:包含用于预测dnn_utils.py的训练和函数调用:包含预测函数

我该如何编写预测函数或处理此错误?