似乎无法理解为什么tf.contrib.layers.zeros_initializer()给出Aterror

时间:2019-03-20 18:00:29

标签: python tensorflow

两个字典为CNN定义权重和偏见

weights = {
#Convolution Layers
'c1': tf.get_variable('W1', shape=(3,3,1,16), initializer=tf.contrib.layers.xavier_initializer()),
'c2': tf.get_variable('W2', shape=(3,3,16,16), initializer=tf.contrib.layers.xavier_initializer()),
'c3': tf.get_variable('W3', shape=(3,3,16,32), initializer=tf.contrib.layers.xavier_initializer()),
'c4': tf.get_variable('W4', shape=(3,3,32,32), initializer=tf.contrib.layers.xavier_initializer()),

#Dense Layers
'd1': tf.get_variable('W5', shape=(7*7*32,128), initializer=tf.contrib.layers.xavier_initializer()),
'd2': tf.get_variable('W6', shape=(128,n_class), initializer=tf.contrib.layers.xavier_initializer()),
}

biases = {
#Convolution Layers
'c1': tf.get_variable('B1', shape=(16), initializer=tf.contrib.layers.zeros_initializer()),
'c2': tf.get_variable('B2', shape=(16), initializer=tf.contrib.layers.zeros_initializer()),
'c3': tf.get_variable('B3', shape=(32), initializer=tf.contrib.layers.zeros_initializer()),

#Dense Layers
'd1': tf.get_variable('B5', shape=(128), initializer=tf.contrib.layers.zeros_initializer()),
'd2': tf.get_variable('B6', shape=(n_class), initializer=tf.contrib.layers.zeros_initializer()),
}

AttributeError:“模块”对象没有属性“ zeros_initializer”

1 个答案:

答案 0 :(得分:0)

我认为它已被弃用,请使用keras.initializers.zeros

a = tf.get_variable('B1', shape=(16), initializer=tf.keras.initializers.zeros())

或者您仍然可以使用compat模块

来访问旧功能。
a = tf.get_variable('B1', shape=(16,), initializer=tf.compat.v1.zeros_initializer())