I have a deep neural network where the weights between layers are stored in a list.
layers[j].weights
I want to incluse the ridge penalty in my cost function. I need then to use something like
tf.nn.l2_loss(layers[j].weights**2 for j in range(self.n_layers))
i.e. the squared sum of all the weights.
In particular the weights are defined as:
>>> avs.layers
[<neural_network.Layer object at 0x10a4b2a90>, <neural_network.Layer object at 0x10ac85080>, <neural_network.Layer object at 0x10b0f3278>, <neural_network.Layer object at 0x10b0eacf8>, <neural_network.Layer object at 0x10b145588>, <neural_network.Layer object at 0x10b165048>, <neural_network.Layer object at 0x10b155ba8>]
>>>
>>> avs.layers[0].weights
<tensorflow.python.ops.variables.Variable object at 0x10b026748>
>>>
How can I do that in tensorflow ?