
Variables:
scope issue:
with tf.variable_scope as scope:
w = tf.get_variable('weight', [1])
Add more losses
weight = tf.get_variable('weights', collections=['variables'])
with tf.variable_scope('weights_norm') as scope:
weights_norm = tf.reduce_sum(
input_tensor = WEIGHT_DECAY_FATOR*tf.pack(
[tf.nn.l2_loss(i) for i in tf.get_collection('weights')]
),
name='weight_norm'
)
# Add the weight decay loss to another collection called losses
tf.add_to_collection('losses', weights_norm)
# Calculate total loss
tf.add_n(tf.get_collection('losses'), name='total_loss')




近期评论