I know that L2 regularization technique to used to reduce over-fitting and penalize large weights. In more than one place I saw that it used like the code below in tensorflow library:
reg = tf.nn.l2_loss(w_conv1) + tf.nn.l2_loss(w_conv2) + \ tf.nn.l2_loss(w_conv3) + tf.nn.l2_loss(w_conv4) + \ tf.nn.l2_loss(w_conv5) + tf.nn.l2_loss(w_fc1) + \ tf.nn.l2_loss(w_out) loss = tf.reduce_mean(loss + reg * beta)
I am confused about how this code penalize weights? the code adds L2 to weights then adding the result to loss. could anyone please explain this for me?