# 3D Conv Training Error

**URL:** https://discourse.julialang.org/t/3d-conv-training-error/26831
**Category:** Machine Learning
**Tags:** flux
**Created:** [July 26, 2019, 7:22am UTC](https://discourse.julialang.org/t/3d-conv-training-error/26831 "2019-07-26T07:22:20Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![MaximilianGelbrecht](https://avatars.discourse-cdn.com/v4/letter/m/e95f7d/32.png) [@MaximilianGelbrecht](https://discourse.julialang.org/u/MaximilianGelbrecht)
#### Post date: [July 26, 2019, 7:22am UTC](https://discourse.julialang.org/t/3d-conv-training-error/26831/1 "2019-07-26T07:22:20Z")

</div>

Hi there,

I encountered an error while setting up a 3D CNN that I dont understand. The problems boils down to this:

While in 2D

```julia
using Flux

a, b = rand(5,10,2,10), rand(5,10,2,10)
m= Chain(Conv((3,3),2=>4,pad=(1,1)), Conv((3,3), 4=>2, pad=(1,1)))
loss(x,y) = Flux.mse(m(x),y)
@time Flux.train!(loss, params(m), [[a,b]], ADAM(0.01))

```

works without problems, in 3D

```julia
a2, b2 = rand(5,10,10,2,10), rand(5,10,10,2,10)
m2= Chain(Conv((3,3,3),2=>4,pad=(1,1,1)), Conv((3,3,3), 4=>2, pad=(1,1,1)))
loss2(x,y) = Flux.mse(m2(x),y)
@time Flux.train!(loss2, params(m2), [[a2,b2]], ADAM(0.01))

```

will result in a dimension mismatch on the training (back/gradient operator) even though `loss2(a2,b2)` works.

Am I doing something wrong here or is this a bug?

Best,  
Max

---

<div class="post-metadata">

### Author: ![Peter\_Stijnman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peter_stijnman/32/9978_2.png) [@Peter\_Stijnman](https://discourse.julialang.org/u/Peter_Stijnman)
#### Post date: [August 27, 2019, 1:25pm UTC](https://discourse.julialang.org/t/3d-conv-training-error/26831/2 "2019-08-27T13:25:45Z")

</div>

Hey Max,

I ran into the same error and think I (finally) fixed it.  
The error that gets displayed, “Dimension mismatch”, is not completely correct or at least confusing. The actual problem is a Type error. Simply changing the first line of the 3D problem to

```julia
a2, b2, = rand(Float32,5,10,10,2,10), rand(Float32,5,10,10,2,10)

```

should fix this error. Hopefully, this is still of some help to you or someone else that stumbles onto the same problem and this forum post 🙂

Best,  
Peter
