[英]How do I define my own operators in TensorFlow
In TensorFlow, we can use tf.nn.l2_loss()
for doing L2 regularization. 在TensorFlow中,我们可以使用
tf.nn.l2_loss()
来进行L2正则化。 Let's say I want to define my own regularization operator for L1 regularization (call it tf.nn.l1_loss()
). 假设我想为L1正则化定义我自己的正则化运算符(称之为
tf.nn.l1_loss()
)。 How would I go about it? 我该怎么办呢? I am having a hard time locating operator definitions in the TensorFlow source code.
我很难在TensorFlow源代码中找到运算符定义。
As the comment suggested, there is a how-to guide for adding an op to TensorFlow . 正如评论所建议的那样,有一个向TensorFlow添加操作的操作指南。 This guide covers adding a new op that is implemented in C++.
本指南介绍了如何添加用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). l1_loss
可以使用现有的逐元素和简化运算符作为Python函数来实现)。 tf.nn.l2_loss
is implemented as a fused op in C++.) tf.nn.l2_loss
在C ++中实现为融合操作的原因。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.