I was writing some simple models and I did not want the Model Loss to be the sum of all L2 Regularizations. I wanted it to be the mean instead. My reason being that having 3 L2 Losses had a huge impact of regularization, taking the mean reduces that impact. In most courses as well, we can take the mean
Any idea on how to approach it in a manner that can generalize well
import tensorflow as tf
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Dense
For the regularization loss penalizzation the sum is embedded in the code when you compile the loss:
As a workaround probably you could create a custom regularizer that you can scale yourself (if you know the total number of regularizers) or you can control your loss more in detail with a custom trainning loop:
Thanks, I was hoping there would be a simple way. Thanks for letting me know
Probably the best way would be the training step as I am not sure how many layers require regularization. I want the solution to be generic and not specific