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++.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.