Is it possible to add an L2 regularization when using the layers defined in tf.layers?
It seems to me that since tf.layers is an high level wrapper, there is no easy way to get access to the filter weights.
With tf.nn.conv2d
regularizer = tf.contrib.layers.l2_regularizer(scale=0.1)
weights = tf.get_variable(
name="weights",
regularizer=regularizer
)
#Previous layers
...
#Second layer
layer 2 = tf.nn.conv2d(
input,
weights,
[1,1,1,1],
[1,1,1,1])
#More layers
...
#Loss
loss = #some loss
reg_variables = tf.get_collection(tf.GraphKeys.REGULARIZATION_LOSSES)
reg_term = tf.contrib.layers.apply_regularization(regularizer, reg_variables)
loss += reg_term
Now what would that look like with tf.layers.conv2d?
Thanks!