質問するログイン新規登録

質問編集履歴

1

修正

2019/06/03 08:23

投稿

ulu
ulu

スコア13

title CHANGED
File without changes
body CHANGED
@@ -11,5 +11,16 @@
11
11
  (読んでいたコードでは以下のように登場していました。↓)
12
12
 
13
13
  ```python
14
+ def leaky_relu(x, alpha=0.2):
15
+ with tf.variable_scope('LeakyReLU'):
16
+ alpha = tf.constant(alpha, dtype=x.dtype, name='alpha')
17
+ @tf.custom_gradient
18
+ def func(x):
19
+ y = tf.maximum(x, x * alpha)
20
+ @tf.custom_gradient
21
+ def grad(dy):
14
- dx = tf.where(y >= 0, dy, dy * alpha)
22
+ dx = tf.where(y >= 0, dy, dy * alpha)
23
+ return dx, lambda ddx: tf.where(y >= 0, ddx, ddx * alpha)
24
+ return y, grad
25
+ return func(x)
15
26
  ```