我想将SELU单元与julia TensorFlow库一起使用。
我该怎么做?
它位于python library。 在此之前,在[pythonbyGünter](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中无法正常工作
答案 0 :(得分:2)
简单地说:
selu(x) = 1.0507select(x.<0, 1.76326exp(x) .- 1.0 , x)
目前,TensorFlow.jl并未导出 where
,但可以将其显示为TensorFlow.Ops.where
。
我个人有点不喜欢它,并且更喜欢使用find
或select
,具体取决于我是否需要索引,或者我是否想要选择输出。 (对我来说,它们是不相关的操作。并且不值得在名称where
上多次发送)
在这种情况下,我们希望稍后使用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