假设这样的代码:
sess.run(tf.initialize_all_variables())
assign_op_0 = embedding_list[0].assign(tf.random_normal([35019, 32], stddev = 0.0))
assign_op_1 = embedding_list[1].assign(tf.random_normal([35019, 32], stddev = 0.0))
sess.run(assign_op_0)
sess.run(assign_op_1)
embedding_list [0]和embedding_list [1]是在第一行代码中初始化的两个变量。现在我想用一些新值覆盖,所以我有以下四行代码,但是,我不知道这是否正确。我甚至无法打印embedding_list [0]和embedding_list [1]的值。当我这样做时:
print(embedding_list[0].eval(session=sess.run))
它有这个错误:
Traceback (most recent call last):
File "/home/zhao/DeepQA-master/main.py", line 29, in <module>
chatbot.main()
File "/home/zhao/DeepQA-master/chatbot/chatbot.py", line 213, in main
print(embedding_list[0].eval(session=self.sess.run))
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/ops/variables.py", line 437, in eval
return self._variable.eval(session=session)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 555, in eval
return _eval_using_default_session(self, feed_dict, self.graph, session)
File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/framework/ops.py", line 3494, in _eval_using_default_session
if session.graph is not graph:
AttributeError: 'function' object has no attribute 'graph'
答案 0 :(得分:1)
尝试如下:
sess.run(tf.initialize_all_variables())
W_0 = tf.Variable(tf.random_normal([35019, 32], stddev = 0.0))
assign_op_0 = W_0.assign(embedding_list[0])
sess.run(assign_op_0)