簡體   English   中英

如何在TensorFlow中使用Python制作分段激活函數?

[英]How to make a piecewise activation function with Python in TensorFlow?

CNN中的活動功能具有以下形式:

abs(X)< tou  f = 1.716tanh(0.667x)
x >= tou     f = 1.716[tanh(2tou/3)+tanh'(2tou/3)(x-tou)]
x <= -tou    f = 1.716[tanh(-2tou/3)+tanh'(-2tou/3)(x+tou)]

tou是一個常數。

因此,在TensorFlow中可以創建自己的激活功能。 我不想用C ++編寫它並重新編譯整個TensorFlow。

如何使用TensorFlow中可用的功能來實現它?

在tensorflow中,如果它包含已經存在的操作很容易編寫自己的激活函數,對於您的情況,您可以使用tf.case

f = tf.case({tf.less(tf.abs(x), tou): lambda: 7.716 * tf.tanh(0.667 * x),
         tf.greater_equal(x, tou): lambda: 1.716 * tf.tanh(2 * tou / 3) + 1.716 * tf.tanh(2 * tou / 3) * (x - tou)},
        default=lambda: 1.716 * tf.tanh(-2 * tou / 3) + 1.716 * tf.tanh(-2 * tou / 3) * (x + tou), exclusive=True)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM