Initialize weights for Flux.Dense

Hello.
I can’t figure out the syntax to initialize the weights for Flux.Dense.

using Flux
w0 = Float32[1, 2, 3, 4]
nn = Dense(4, 1, relu; initW = w0)

produces the following error.

MethodError: objects of type Array{Float32,2} are not callable

so it seems the initW needs to be a function of some kind.

I also tried

nn.W = w0

and got error

setfield! immutable struct of type Dense cannot be changed

which seems to be saying I can’t change the Dense object (?).

Thanks for looking!

(Julia 1.4.2 and Flux v0.11.0)

you need to provide functions for initW and initb:

using Flux

w0 = Float32[1, 2, 3, 4]
nn = Dense(4, 1, relu;
    initW = (out, in) -> w0, initb = out -> zeros(out))

# now you can verify it
nn.W
#4-element Array{Float32,1}:
# 1.0
# 2.0
# 3.0
# 4.0

However, the product * of initW and whatever you feed nn must be defined (and the addition .+ between that and initb). For example:

w0 = [1 2 3 4; 1 2 3 4]
nn([1, 2, 3, 4))
#2-element Array{Float64,1}:
# 30.0
# 30.0