tf.layers.batch_normalization不在密集层的for循环中工作

时间:2018-02-14 23:12:58

标签: tensorflow

我正在尝试在GCMLE中使用batch_normalization并且我收到错误:

import pandas.io.formats.excel
pandas.io.formats.excel.header_style = None

我的代码如下:

ValueError: Variable dense/batch_norm/batch_normalization/gamma already exists, disallowed. Did you mean to set reuse=True or reuse=tf.AUTO_REUSE in VarScope?

我还按照说明添加了update_ops:

with tf.variable_scope('hidden_layer'):    
  for layer_size in hidden_units:
      hidden_layer = tf.layers.dense(hidden_layer,layer_size, activation=tf.nn.relu)
      hidden_layer = tf.layers.batch_normalization(hidden_layer, axis = -1, training = mode == Modes.TRAIN)

我对错误原因的第一个猜测是它正在尝试重用在for循环update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS) with tf.control_dependencies(update_ops): train_op = tf.train.AdamOptimizer(learning_rate=params.learning_rate, epsilon = params.epsilon) gradients, variables = zip(*train_op.compute_gradients(loss)) optimize = train_op.apply_gradients(zip(gradients, variables), global_step=global_step) 中创建的变量,但重用文档表明这是hidden_layer/dense/batch_norm/batch_normalization/gamma - 如果这个问题是由for循环创建,第二次通过循环不会有名称Boolean, whether to reuse the weights of a previous layer by the same name.?如果我只添加一个隐藏层,代码工作正常,所以我不确定如何调整。

0 个答案:

没有答案