tf.get_variable('w', [x.get_shape()[-1], 1], initializer=tf.random_normal_initializer(0, 1)) 为什么总是报错?
发布于 12天前 作者 gufenfei1122 来自问答

tf.get_variable('w', [x.get_shape()[-1], 1], initializer=tf.random_normal_initializer(0, 1))总是报错

若改成tf.Variable 的形式,应如何修改?请指教!


2回复

TypeError Traceback (most recent call last) in 5 # (3072, 1) 6 #w = tf.get_variable('w', [x.get_shape()[-1], 1], initializer=tf.random_normal_initializer(0, 1)) ----> 7 w = tf.Variable(tf.random_normal([x.get_shape()[-1], 1]), name='w',initializer=tf.random_normal_initializer(0, 1)) 8 # (1, ) 9 b = tf.get_variable([1], 'b', initializer=tf.constant_initializer(0.0)) E:\ProgramData\Anaconda3\envs\tensorflow\lib\site-packages\tensorflow_core\python\ops\variables.py in __call__(cls, *args, **kwargs) 255 def __call__(cls, *args, **kwargs): 256 if cls is VariableV1: --> 257 return cls._variable_v1_call(*args, **kwargs) 258 elif cls is Variable: 259 return cls._variable_v2_call(*args, **kwargs) TypeError: _variable_v1_call() got an unexpected keyword argument 'initializer'

已解决 w = tf.Variable(tf.random_normal([x.get_shape()[-1], 1],mean=0.0, stddev=1.0, dtype=tf.float32), name='w') b = tf.Variable(tf.random_normal([1],mean=0.0, dtype=tf.float32), 'b')

回到顶部