如何在 Flux.jl 中初始化权重
How to initialize weights in Flux.jl
我想为模型中的特定层初始化一些权重和偏差。 Flux.jl
这怎么可能?
大多数层函数,例如 Dense
和 Conv
都采用权重和偏差。您可以通过执行 ? Dense
或 ? Conv
查看每个函数的定义,这将表明,例如,可以通过执行以下操作简单地使用权重和条调用 Dense 函数:Dense(W::AbstractMatrix, [bias, σ])
并且对于Conv
函数,像这样:
julia> weight = rand(3, 4, 5);
julia> bias = zeros(5);
julia> c1 = Conv(weight, bias, sigmoid) # expects 1 spatial dimension
Conv((3,), 4=>5, σ)
其中 sigmoid
是 sigmoid 函数的语法糖,通常表示为 σ()
。
我想为模型中的特定层初始化一些权重和偏差。 Flux.jl
这怎么可能?
大多数层函数,例如 Dense
和 Conv
都采用权重和偏差。您可以通过执行 ? Dense
或 ? Conv
查看每个函数的定义,这将表明,例如,可以通过执行以下操作简单地使用权重和条调用 Dense 函数:Dense(W::AbstractMatrix, [bias, σ])
并且对于Conv
函数,像这样:
julia> weight = rand(3, 4, 5);
julia> bias = zeros(5);
julia> c1 = Conv(weight, bias, sigmoid) # expects 1 spatial dimension
Conv((3,), 4=>5, σ)
其中 sigmoid
是 sigmoid 函数的语法糖,通常表示为 σ()
。