# \[Solved\]Flux.jl: can it be used to train networks with multiple distinct inputs?

**URL:** <https://discourse.julialang.org/t/solved-flux-jl-can-it-be-used-to-train-networks-with-multiple-distinct-inputs/16498>\
**Category:** Machine Learning\
**Created:** [October 18, 2018, 3:44pm UTC](https://discourse.julialang.org/t/solved-flux-jl-can-it-be-used-to-train-networks-with-multiple-distinct-inputs/16498 "2018-10-18T15:44:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![thvhauwe](https://avatars.discourse-cdn.com/v4/letter/t/59ef9b/32.png) [@thvhauwe](https://discourse.julialang.org/u/thvhauwe)\
**Post date:** [October 18, 2018, 3:44pm UTC](https://discourse.julialang.org/t/solved-flux-jl-can-it-be-used-to-train-networks-with-multiple-distinct-inputs/16498/1 "2018-10-18T15:44:55Z")

</div>

Similar network in Keras: [The Functional API](https://keras.io/getting-started/functional-api-guide/#multi-input-and-multi-output-models)

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)

```

---

<div class="post-metadata">

**Author:** ![thvhauwe](https://avatars.discourse-cdn.com/v4/letter/t/59ef9b/32.png) [@thvhauwe](https://discourse.julialang.org/u/thvhauwe)\
**Post date:** [October 22, 2018, 2:57pm UTC](https://discourse.julialang.org/t/solved-flux-jl-can-it-be-used-to-train-networks-with-multiple-distinct-inputs/16498/2 "2018-10-22T14:57:02Z")

</div>

SOLVED:

1. by changing the line in the optimizer:  
Flux.Optimise.SGD([W1,W2,W3,b1,b2,b3]  
to  
using Flux.Tracker  
Flux.Optimise.SGD(Params([W1,W2,W3,b1,b2,b3]),…

2. abandon Zipped\_data and writing custom function to obtain the Array(Tuple(Array( structure required for Flux.Train!
