tensorflow - 如何在 TensorFlow.jl 中实现 SELU?

标签 tensorflow julia

我想将 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

我个人有点不喜欢它,并且更喜欢使用 findselect 取决于我是否需要索引,或者如果我想选择输出。 (对我来说,它们是不相关的操作。并且不值得在名称 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/

相关文章:

python - 将 mnist 图像读入 Tensorflow

python - 为什么我的 TensorFlow 神经网络的 XOR 精度只有 0.5 左右?

python - 使用 tf.Dataset 训练的模型进行推理

multithreading - 使用多线程未报告 undefined variable 错误

parallel-processing - 在 Julia 的函数中使用 addprocs() 和 pmap()

python - Keras/ tensorflow : Get predictions or output of all layers efficiently

python - 加载视频数据集(Keras)

julia - 如何减少gadfly中的点边框线宽度

vector - Julia - 按元素检查向量 x 的元素是否在向量 y 中

julia - 从键和值数组创建字典