# How can I add to ML model together in Flux

**URL:** https://discourse.julialang.org/t/how-can-i-add-to-ml-model-together-in-flux/26271
**Category:** Machine Learning
**Created:** [July 12, 2019, 2:56am UTC](https://discourse.julialang.org/t/how-can-i-add-to-ml-model-together-in-flux/26271 "2019-07-12T02:56:21Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Lyupinpin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lyupinpin/32/9295_2.png) [@Lyupinpin](https://discourse.julialang.org/u/Lyupinpin)
#### Post date: [July 12, 2019, 2:56am UTC](https://discourse.julialang.org/t/how-can-i-add-to-ml-model-together-in-flux/26271/1 "2019-07-12T02:56:21Z")

</div>

Like I have two model now  
M1=Chain(  
Dense(2,10),  
Dense(10,10,relu),  
Dense(10,10,relu),  
Dense(10,10,relu),  
Dense(10,1)  
)  
M2=Chain(  
Dense(2,10),  
Dense(10,10,relu),  
Dense(10,10,relu),  
Dense(10,10,relu),  
Dense(10,1)  
)

and the model I want to train is model=M1+M2  
but if I just add them Flux.params(M) shows nothing and I can not train it .

---

<div class="post-metadata">

### Author: ![DoktorMike](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/doktormike/32/2736_2.png) [@DoktorMike](https://discourse.julialang.org/u/DoktorMike)
#### Post date: [July 12, 2019, 4:59am UTC](https://discourse.julialang.org/t/how-can-i-add-to-ml-model-together-in-flux/26271/2 "2019-07-12T04:59:15Z")

</div>

Are you trying to create an ensemble? I’m not sure of your use case but it seems like to independent models of identical structure. In this case you should run two training sessions and combine them after they’ve both been fitted to your data.

---

<div class="post-metadata">

### Author: ![Lyupinpin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lyupinpin/32/9295_2.png) [@Lyupinpin](https://discourse.julialang.org/u/Lyupinpin)
#### Post date: [July 12, 2019, 5:43am UTC](https://discourse.julialang.org/t/how-can-i-add-to-ml-model-together-in-flux/26271/3 "2019-07-12T05:43:21Z")

</div>

Actually, I want the M1 minimize a loss functiona(Loss1) and M=M1+M2 minimize another loss function(Loss2) at the same time. The finial Loss Funcition is something like Loss= Loss1[M1(x)] + \beta Loss2[M(x)].
