-1

我已经定义了 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."
4

1 回答 1

1

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

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

缺少一个等号name="y_pred"。它应该是

train_prediction = tf.nn.softmax( logits, name = "y_pred" )
于 2018-04-26T23:28:38.250 回答