buriburisuri / sugartensor

A slim tensorflow wrapper that provides syntactic sugar for tensor variables. This library will be helpful for practical deep learning researchers not beginners.
MIT License
372 stars 63 forks source link

leaky relu slope, parameter? #11

Closed aosokin closed 7 years ago

aosokin commented 7 years ago

Hi, would it be possible to convert the slope of the negative piece of leaky relu to a parameter instead of hard-coded value?

buriburisuri commented 7 years ago

@aosokin

You can do it as follows:

@tf.sg_sugar_func
def my_relu(x, opt):
   return tf.select(tf.greater(x, 0), x, opt.slope * x)

tf.sg_inject_func(my_relu)

.
.
.

y = x.sg_conv().my_relu(slope=0.01)

# or

with tf.sg_scope(slope=0.01)
  y = x.sg_conv().my_relu() 

.
.

Thanks

aosokin commented 7 years ago

Thanks, this works! I suggest adding leaky ReLU slope as a parameter to the main code.