我想将 SELU 单元与 julia TensorFlow 库一起使用。
我该怎么做?
它位于 python library 。 在此之前,[Günter 的 python]( https://github.com/bioinf-jku/SNNs/blob/master/SelfNormalizingNetworks_MLP_MNIST.ipynb]
def selu(x):
with ops.name_scope('elu') as scope:
alpha = 1.6732632423543772848170429916717
scale = 1.0507009873554804934193349852946
return scale*tf.where(x>=0.0, x, alpha*tf.nn.elu(x))
where
在 TensorFlow.jl 中似乎无法正常工作
最佳答案
很简单:
selu(x) = 1.0507select(x.<0, 1.76326exp(x) .- 1.0 , x)
where
当前未由 TensorFlow.jl 导出,但可以发现它未导出为 TensorFlow.Ops.where
。
我个人有点不喜欢它,并且更喜欢使用 find
或 select
取决于我是否需要索引,或者如果我想选择输出。 (对我来说,它们是不相关的操作。并且不值得在名称 where
上进行多次分派(dispatch))
在这种情况下,我们想要后者,所以使用 select
如果您想为生成的节点命名,您可以对这个函数进行一些改进。 但这就是真正要做的事情。
使用示例:
julia> using TensorFlow
julia> sess=Session()
Session(Ptr{Void} @0x00007fa626702170)
julia> selu(x) = 1.0507select(x.<0, 1.76326exp(x) .- 1.0 , x)
selu (generic function with 1 method)
julia> run(sess, selu(constant(1.0)))
1.0507
julia> run(sess, selu(constant(0.0)))
0.0
julia> run(sess, selu(constant(-1000.0)))
-1.0507
julia> run(sess, selu(constant(1000.0)))
1050.7
关于tensorflow - 如何在 TensorFlow.jl 中实现 SELU?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46786317/