Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python TypeError:无法将提要dict键解释为张量:名称';保存/常量:0';指不存在的张量_Python_Tensorflow_Pygame_Reinforcement Learning_Q Learning - Fatal编程技术网

Python TypeError:无法将提要dict键解释为张量:名称';保存/常量:0';指不存在的张量

Python TypeError:无法将提要dict键解释为张量:名称';保存/常量:0';指不存在的张量,python,tensorflow,pygame,reinforcement-learning,q-learning,Python,Tensorflow,Pygame,Reinforcement Learning,Q Learning,从该文件: 我已经更新了台词 #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

从该文件:

我已经更新了台词

#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')
以及:

以及:

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('./'))
    # ////
要尝试恢复模型,但出现以下错误:

TypeError:无法将提要索引键解释为张量:名称“save/Const:0”引用的张量不存在。图形中不存在“save/Const”操作

当我尝试这个:

 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")  
我得到这个错误:

“名称'W_conv1:0'表示不存在的张量。图形中不存在运算'W_conv1'

为什么会这样? 我已经在pygame中创建了我的游戏,我正在尝试将它连接到RL。 我想确保我可以保存和加载我的进度。我只是对如何保存和加载的逻辑有问题

提前谢谢

 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")