十位数上的值错误

2024-04-23 23:25:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用tensorflow工具箱编写了一个简单的代码,如下所示:

import tensorflow as tf
import numpy as np
if __name__=="__main__":
   inp = np.random.randint(1,3,(1,20,300,1))
   inputs = tf.convert_to_tensor(inp,dtype=tf.float32)
   with tf.variable_scope('convpool1') as scope:
       kernel = tf.get_variable('weights',[1,300,1,1],initializer=tf.truncated_normal_initializer(stddev=5e-2,dtype=tf.float32))
       conv1 = tf.nn.conv2d(inputs,kernel,[1,1,1,1],padding='VALID')

   init = tf.initialize_all_variables()
   with tf.Session() as sess:
        sess.run(init)
        with tf.variable_scope('convpool1'):
            k_ = sess.run(kernel)
            c1_ =sess.run(conv1)

当我第一次运行此代码时,它可以工作,但当我再次运行相同的代码时,它会引发一个错误:

^{pr2}$

我重新启动IDE(spyder),运行这段代码,就可以了再说一遍。什么可能是这个错误的根源,以及我如何解决它?谢谢你的时间!在


Tags: run代码importtftensorflowaswithnp