基于HiLens Studio開發行人檢測與跟蹤應用
995
2022-05-29
ReLU、LeakyReLU
ReLU作為激活函數被廣泛應用于各種深度神經網絡中。在這篇博客中,我主要記錄一下它和它的變種在caffe中的實現。
先看下來自wikipedia的一張示意圖,圖中藍色的線表示的就是ReLU函數。
ReLU激活函數極為。而LeakyReLU則是其變體,其中,是一個小的非零數。
綜上,在caffe中,ReLU和LeakyReLU都包含在relu_layer中。
在后向傳播過程中,ReLU做如下運算:
// Message that stores parameters used by ReLULayer
message ReLUParameter {
// Allow non-zero slope for negative inputs to speed up optimization
// Described in:
// Maas, A. L., Hannun, A. Y., & Ng, A. Y. (2013). Rectifier nonlinearities
// improve neural network acoustic models. In ICML Workshop on Deep Learning
// for Audio, Speech, and Language Processing.
optional float negative_slope = 1 [default = 0]; //如之前分析的,默認值0即為ReLU,非零則為LeakyReLU
enum Engine {
DEFAULT = 0;
CAFFE = 1;
CUDNN = 2;
}
optional Engine engine = 2 [default = DEFAULT]; //運算引擎選擇,一般選擇默認
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
PReLU
PReLU,即Parametric ReLU,是何凱明組提出的一種改進ReLU。它的數學表示為?,其中是可學習參數。當為固定的非零較小數時,它等價于LeakyReLU;當它為0時,PReLU等價于ReLU。它的后向傳播進行如下計算:
message PReLUParameter {
// Parametric ReLU described in K. He et al, Delving Deep into Rectifiers:
// Surpassing Human-Level Performance on ImageNet Classification, 2015.
// Initial value of a_i. Default is a_i=0.25 for all i.
optional FillerParameter filler = 1; //默認填充,a_i的初始值為0.25
// Whether or not slope parameters are shared across channels.
optional bool channel_shared = 2 [default = false]; //是否通道共享參數,默認為不共享
}
1
2
3
4
5
6
7
8
9
Tensorflow中實現leakyRelu操作(高效)
從github上轉來,實在是厲害的想法,什么時候自己也能寫出這種精妙的代碼就好了
原地址:
簡易高效的LeakyReLu實現
代碼如下: 我做了些改進,因為實在tensorflow中使用,就將原來的abs()函數替換成了tf.abs()
import tensorflow as tfdef LeakyRelu(x, leak=0.2, name="LeakyRelu"): with tf.variable_scope(name): f1 = 0.5 * (1 + leak) f2 = 0.5 * (1 - leak) return f1 * x + f2 * tf.abs(x) # 這里和原文有不一樣的,我沒試驗過原文的代碼,但tf.abs()肯定是對的
TensorFlow
版權聲明:本文內容由網絡用戶投稿,版權歸原作者所有,本站不擁有其著作權,亦不承擔相應法律責任。如果您發現本站中有涉嫌抄襲或描述失實的內容,請聯系我們jiasou666@gmail.com 處理,核實后本網站將在24小時內刪除侵權內容。