Similar network in Keras: The Functional API
I’m getting errors when running the following basic example code trying to train a network with two inputs and 1 output. The network is made up out of a left branch and a right branch
using Flux
nINPUTS=1024
nHIDDEN=353
nOUTPUTS=54
W1 = param(rand(nHIDDEN, nINPUTS))
b1 = param(rand(nHIDDEN))
layer1(x) = W1 * x .+ b1
W2 = param(rand(nOUTPUTS, nHIDDEN))
b2 = param(rand(nOUTPUTS))
layer2(x) = W2 * x .+ b2
left_branch(x) = layer2(relu.(layer1(x)))
W3 = param(ones(nOUTPUTS,nOUTPUTS))
b3 = param(zeros(nOUTPUTS))
layer3(y) = W3 * y .+ b3
right_branch(y)=layer3(y)
model(A,B)=left_branch(A) .+ right_branch(B)
da,db,dc = rand(nINPUTS),ones(nOUTPUTS),rand(nOUTPUTS)
Zipped_Data = zip(da,db,dc)
loss(x,y,z) = Flux.mse(model(x,y),z)
optSGD=Flux.Optimise.SGD([W1,W2,W3,b1,b2,b3], η = 0.01)
Flux.train!(loss,Zipped_Data,optSGD)