TypeError: Cannot interpret feed_dict key as Tenso

2019-07-22 15:08发布

问题:

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!