【问题标题】:"The name 'y_pred:0' refers to a Tensor which does not exist. The operation, 'y_pred', does not exist in the graph."“名称‘y_pred:0’指的是一个不存在的张量。操作‘y_pred’在图中不存在。”
【发布时间】:2018-04-26 23:17:54
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

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

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

    缺少来自name="y_pred" 的等号。应该是

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

    【讨论】:

      猜你喜欢
      • 2018-12-27
      • 2018-01-21
      • 1970-01-01
      • 2018-05-03
      • 1970-01-01
      • 2019-03-18
      • 2019-12-06
      • 1970-01-01
      • 2019-07-25
      相关资源
      最近更新 更多