def _variable_with_weight_decay(name, shape, wd = 0.0):
"""Helper to create an initialized Variable with weight decay.
Note that the Variable is initialized with a xavier initialization.
A weight decay is added only if one is specified.
#Args:
name: name of the variable
shape: list of ints
wd: add L2Loss weight decay multiplied by this float. If None, weight
decay is not added for this Variable.
Returns:
Variable Tensor
"""
var = _variable_on_cpu(name, shape, tf.contrib.layers.xavier_initializer())
# print("change var")
# var = tf.Variable(tf.truncated_normal(shape, mean= 0.0, stddev = 1.0), name = name)
if wd != 0.0:
weight_decay = tf.mul(tf.nn.l2_loss(var), wd, name='weight_loss')
tf.add_to_collection('losses', weight_decay)
return var
评论列表
文章目录