tf.less(x,y)

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/weixin_38145317/article/details/98742232

 tf.less返回了两个张量各元素比较(x<y)得到的真假值组成的张量

import tensorflow as tf
A=[[1,2,3],
   [4,5,6]]
i=[[1,2,3],
   [1,2,3]]
r = tf.less(i, A)
with tf.Session() as sess:
    print(sess.run(r))#[[False False False]
                      # [ True  True  True]]

再来看损失函数的构造:

loss= \left\{\begin{matrix} 0.5\sigma ^2e^2&if |e|<\frac{1}{\sigma^2}\\ |e|-\frac{0.5}{\sigma ^2}& other \end{matrix}\right.

其中,e为误差,\sigma =3,代码实现为

regression_diff = regression - regression_target
        regression_diff = keras.backend.abs(regression_diff)
        regression_loss = backend.where(
            keras.backend.less(regression_diff, 1.0 / sigma_squared),
            0.5 * sigma_squared * keras.backend.pow(regression_diff, 2),
            regression_diff - 0.5 / sigma_squared
        )

 

猜你喜欢

转载自blog.csdn.net/weixin_38145317/article/details/98742232