TypeError: Cannot interpret feed_dict key as Tensor: The name 'save/Const:0' refers to a Tensor which does not exist

一世执手 提交于 2019-12-24 08:47:43

问题


From this file: https://github.com/llSourcell/pong_neural_network_live/blob/master/RL.py

I've updated the lines

#first convolutional layer. bias vector
#creates an empty tensor with all elements set to zero with a shape

W_conv1 = tf.Variable(tf.zeros([8, 8, 4, 32]) , name='W_conv1')
b_conv1 = tf.Variable(tf.zeros([32]), name='b_conv1')

W_conv2 = tf.Variable(tf.zeros([4, 4, 32, 64]), name='W_conv2')
b_conv2 = tf.Variable(tf.zeros([64]), name='b_conv2')

W_conv3 = tf.Variable(tf.zeros([3, 3, 64, 64]), name='W_conv3')
b_conv3 = tf.Variable(tf.zeros([64]), name='b_conv3')

W_fc4 = tf.Variable(tf.zeros([3136, 784]), name='W_fc4')
b_fc4 = tf.Variable(tf.zeros([784]), name='b_fc4')

W_fc5 = tf.Variable(tf.zeros([784, ACTIONS]), name='W_fc5')
b_fc5 = tf.Variable(tf.zeros([ACTIONS]), name='b_fc5')

and:

saver.save(sess, './' + 'pong' + '-dqn', global_step = timestamp)

and in:

def main():
    # ////
    tf.reset_default_graph()
    imported_meta = tf.train.import_meta_graph('./' + 'pong' + '-dqn-' + '48000' + '.meta')
    imported_meta.restore(sess, tf.train.latest_checkpoint('./'))
    # ////

To try and restore the model but I get this error:

TypeError: Cannot interpret feed_dict key as Tensor: The name 'save/Const:0' refers to a Tensor which does not exist. The operation, 'save/Const', does not exist in the graph.

When I try this:

 graph = tf.get_default_graph() 
 W_conv1 = graph.get_tensor_by_name("W_conv1:0")
 b_conv1 = graph.get_tensor_by_name("wb_conv1:0") 
 W_conv2 = graph.get_tensor_by_name("W_conv2:0")
 b_conv2 = graph.get_tensor_by_name("wb_conv2:0") 
 W_conv3 = graph.get_tensor_by_name("W_conv3:0")
 b_conv3 = graph.get_tensor_by_name("b_conv3:0") 
 W_fc4 = graph.get_tensor_by_name("W_fc4:0")
 b_fc4 = graph.get_tensor_by_name("b_fc4:0") 
 W_fc5 = graph.get_tensor_by_name("W_fc5:0")
 b_fc5 = graph.get_tensor_by_name("b_fc5:0")  

I get this error:

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

Why is this happening? I've created my game in pygame and I'm trying to connect it to the RL. I'd like to make sure I can save and load my progress. I'm just having trouble with the logic of how to save and load.

Thanks in advance!

来源:https://stackoverflow.com/questions/47085859/typeerror-cannot-interpret-feed-dict-key-as-tensor-the-name-save-const0-ref

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!