In TensorFlow, we can use tf.nn.l2_loss()
for doing L2 regularization. Let's say I want to define my own regularization operator for L1 regularization (call it tf.nn.l1_loss()
). How would I go about it? I am having a hard time locating operator definitions in the TensorFlow source code.
As the comment suggested, there is a how-to guide for adding an op to TensorFlow. This guide covers adding a new op that is implemented in C++. In general, you should do this in the following situations:
l1_loss
could be implemented using the existing element-wise and reduction operators as a Python function).tf.nn.l2_loss
is implemented as a fused op in C++.)If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With