新手求助0.0关于global_variables_initializer
发布于 1月前 作者 VChina 来自问答

这是运行的错误信息

  Traceback (most recent call last):

File "a03.py", line 16, in <module>
init = tf.global_variables_initializer()
AttributeError: 'module' object has no attribute 'global_variables_initializer'#coding:utf-8

#两层
import tensorflow as tf

#定义输入和参数
x = tf.constant([[0.7,0.5]])
w1 = tf.Variable(tf.compat.v2.random.normal([2,3],stddev=1,seed=1))
w2 = tf.Variable(tf.compat.v2.random.normal([3,1],stddev=1,seed=1))

#定义前向传播过程
a = tf.matmul(x,w1)
y = tf.matmul(a,w2)

#会话计算
with tf.compat.v1.Session() as sess:
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
print("y in a03.py is:\n",sess.run(y))



回到顶部