"名称' y_pred:0'是指不存在的张量。图表中不存在' y_pred'操作。"

时间:2018-04-26 23:17:54

标签: python tensorflow machine-learning deep-learning convolutional-neural-network

我已经定义了y_pred,但是,它仍然给出了这个错误。任何形式的帮助都会很好。

with graph.as_default():

# Input data 
tf_train_dataset = tf.placeholder(
    tf.float32, shape=(batch_size, image_size, image_size, num_channels),name 
= 'x_train')
tf_train_labels = tf.placeholder( 
    tf.float32, shape=(batch_size, num_labels),name="y_train")
tf_valid_dataset = tf.constant(valid_dataset)
tf_test_dataset = tf.constant(test_dataset)

........

train_prediction = tf.nn.softmax(logits,name"y_pred")
#print(train_prediction.shape)
valid_prediction = tf.nn.softmax(model(tf_valid_dataset))
test_prediction = tf.nn.softmax(model(tf_test_dataset))

在预测步骤中:

  ...
  y_pred = graph.get_tensor_by_name("y_pred:0")
  ...



KeyError: "The name 'y_pred:0' refers to a Tensor which does not exist. The 
operation, 'y_pred', does not exist in the graph."

1 个答案:

答案 0 :(得分:0)

不确定这只是复制+粘贴错误,而是

train_prediction = tf.nn.softmax(logits,name"y_pred")

错过name="y_pred"的等号。它应该是

train_prediction = tf.nn.softmax( logits, name = "y_pred" )