# Flux with Matrix input dimensions

**URL:** https://discourse.julialang.org/t/flux-with-matrix-input-dimensions/43610
**Category:** Machine Learning
**Tags:** flux
**Created:** [July 24, 2020, 10:11am UTC](https://discourse.julialang.org/t/flux-with-matrix-input-dimensions/43610 "2020-07-24T10:11:25Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Ruan\_Stander](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ruan_stander/32/11304_2.png) [@Ruan\_Stander](https://discourse.julialang.org/u/Ruan_Stander)
#### Post date: [July 24, 2020, 10:11am UTC](https://discourse.julialang.org/t/flux-with-matrix-input-dimensions/43610/1 "2020-07-24T10:11:25Z")

</div>

Hi

Just started using flux, cant get on top of input/layer dimensions where input is a matrix

Adapting [https://github.com/FluxML/model-zoo/blob/master/vision/mnist/mlp.jl](https://github.com/FluxML/model-zoo/blob/master/vision/mnist/mlp.jl) to my input space but its not working

My Input set is Vector{Array{Array{Float32,2},1}}: Vector of 5x10 Matrices of Float32  
Output set is an Array of 1’s and 0’s

I use flatten : xtrain = Flux.flatten(xtrain)  
like the examples does to reduce to Array{Array{Float32,2},2}  
I use the Dataoader like the example does:

```
train_data = DataLoader(xtrain, ytrain, batchsize=32, shuffle=true)
test_data = DataLoader(xtest, ytest, batchsize=32)

```

I use the model:  
function build\_model(; imgsize=(5,10,1), nclasses=2)  
return Chain(  
Dense(prod(imgsize), 32, relu),  
Dense(32, nclasses,softmax))  
end

I call @epochs args.epochs Flux.train!(loss, Flux.params(m), train\_data, opt, cb = evalcb)  
then the loss function gives an error  
loss(x,y) = logitcrossentropy(m(x), y)

When I debug its the evaluation of m(x)  
“Error: DimensionMismatch(“matrix A has dimensions (32,50), matrix B has dimensions (1,32)”)”  
32 is the size of the hidden layer  
50 is the size of the input matrix  
32 is the size of a batch

Any help/insight will be appreciated

Thanks

---

<div class="post-metadata">

### Author: ![Ruan\_Stander](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ruan_stander/32/11304_2.png) [@Ruan\_Stander](https://discourse.julialang.org/u/Ruan_Stander)
#### Post date: [July 26, 2020, 11:32pm UTC](https://discourse.julialang.org/t/flux-with-matrix-input-dimensions/43610/2 "2020-07-26T23:32:54Z")

</div>

Managed to solve myself by changing the input definition to 5x10xN

---

<div class="post-metadata">

### Author: ![Carboxyl](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/carboxyl/32/26950_2.png) [@Carboxyl](https://discourse.julialang.org/u/Carboxyl)
#### Post date: [March 12, 2023, 6:30pm UTC](https://discourse.julialang.org/t/flux-with-matrix-input-dimensions/43610/3 "2023-03-12T18:30:15Z")

</div>

Thank you for writing back with a solution! This helped me a lot!
