【问题标题】:Tensorflow variable/graph key missing while reloading the model in Python 3.6在 Python 3.6 中重新加载模型时缺少 Tensorflow 变量/图形键
【发布时间】:2018-11-02 10:38:42
【问题描述】:

错误信息:

NotFoundError:从检查点恢复失败。这很可能是由于检查点中缺少变量名称或其他图形键。请确保您没有根据检查点更改预期的图表。原始错误:

""" PLACEHOLDER """
x=tf.placeholder(tf.float32,shape=[None,784])
y_true=tf.placeholder(tf.float32,shape=[None,4])


Weight=tf.global_variables()
bias=tf.global_variables()

""" LAYERS:"""

"the image input layer 28*28 input"
x_image = tf.reshape(x,[-1,28,28,1])

"""first convolution, using 6*6 filter, and then max pooling 2by2, final 
output will have depth 32
here we are calculating 32 features
"""
convo_1 = convolutional_layer(x_image,shape=[6,6,1,32])
convo_1_pooling = max_pool_2by2(convo_1)

"""first convolution, using 6*6 filter, and then max pooling 2by2, final 
output will have 64
features hence depth 64
"""
convo_2 = convolutional_layer(convo_1_pooling,shape=[6,6,32,64])
convo_2_pooling = max_pool_2by2(convo_2)

"flattening the output of the last pooling layer to fuly connect it"
convo_2_flat = tf.reshape(convo_2_pooling,[-1,7*7*64])
Wt,bs=normal_full_layer(convo_2_flat,1024)#1024 nodes in the final layer

full_layer_one = tf.nn.relu(tf.matmul(convo_2_flat,Wt)+bs)

# NOTE THE PLACEHOLDER HERE!
hold_prob = tf.placeholder(tf.float32)
full_one_dropout = tf.nn.dropout(full_layer_one,keep_prob=hold_prob) 

Weight, bias= normal_full_layer(full_one_dropout,2)

y_pred=tf.matmul(full_one_dropout,Weight)+bias

"""INITIALIZE VARIABLES"""
init = tf.global_variables_initializer()

"""Add ops to save and restore all the variables"""
saver = tf.train.Saver()

"""Later, launch the model, use the saver to restore variables from disk, 
and
# do some work with the model"""

with tf.Session() as sess:
   # Restore variables from disk.
   saver.restore(sess,SAVE_PATH)
   print("Model restored.")

【问题讨论】:

  • 这是调用保存模型的代码,因此在计算 y_pred 之后我没有用来计算损失函数(我已经删除了那部分代码)我只想要预测的 y 值数组对于我通过的输入 x 数组。

标签: python-3.x tensorflow conv-neural-network


【解决方案1】:

如果你使用spyder,请重启内核!它可以很好地工作。

【讨论】:

  • 请考虑添加更多详细信息
猜你喜欢
  • 2022-01-17
  • 2021-08-06
  • 1970-01-01
  • 2021-09-08
  • 1970-01-01
  • 2021-06-21
  • 2016-09-17
  • 2018-03-07
  • 1970-01-01
相关资源
最近更新 更多