# Flux.jl DimensionMismatch(3 vs 4)

**URL:** <https://discourse.julialang.org/t/flux-jl-dimensionmismatch-3-vs-4/79650>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [April 18, 2022, 7:55pm UTC](https://discourse.julialang.org/t/flux-jl-dimensionmismatch-3-vs-4/79650 "2022-04-18T19:55:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![juzikaster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juzikaster/32/35515_2.png) [@juzikaster](https://discourse.julialang.org/u/juzikaster)\
**Post date:** [April 18, 2022, 7:55pm UTC](https://discourse.julialang.org/t/flux-jl-dimensionmismatch-3-vs-4/79650/1 "2022-04-18T19:55:42Z")

</div>

I am using conv network model from [this repo](https://github.com/FluxML/model-zoo/blob/master/vision/conv_mnist/conv_mnist.jl)  
And when i try to use my image i am getting this error:

```julia-auto
ERROR: LoadError: DimensionMismatch("Rank of x and w must match! (3 vs. 4)")

```

As i know 1 is for RGB and (28, 28) for dimension but for what stands the fourth number?

# How i upload image:

```julia-auto
img = load("30.jpg")
imresize(img, (28, 28))
imgg = Gray.(img)
mat = convert(Array{Float64}, imgg)
model(reshape(mat, (1, 28, 28)))

```

# Model:

```julia-auto
function LeNet5(; imgsize=(28,28,1), nclasses=10)
    out_conv_size = (imgsize[1]÷4 - 3, imgsize[2]÷4 - 3, 16)

    return Chain(
                Conv((5, 5), imgsize[end]=>6, relu),
                MaxPool((2, 2)),
                Conv((5, 5), 6=>16, relu),
                MaxPool((2, 2)),
                flatten,
                Dense(prod(out_conv_size), 120, relu),
                Dense(120, 84, relu),
                Dense(84, nclasses)
          )
end

```

### Image is from MNIST dataset so its already 28x28 and in .jpg format

---

<div class="post-metadata">

**Author:** ![juzikaster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juzikaster/32/35515_2.png) [@juzikaster](https://discourse.julialang.org/u/juzikaster)\
**Post date:** [April 18, 2022, 8:29pm UTC](https://discourse.julialang.org/t/flux-jl-dimensionmismatch-3-vs-4/79650/2 "2022-04-18T20:29:14Z")

</div>

### So i fixed error by reshaping my array like:

```julia-auto
reshape(mat, (28, 28, 1, :))

```

But i still don`t really understand what 4th dim stands for

---

<div class="post-metadata">

**Author:** ![johnbb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnbb/32/34233_2.png) [@johnbb](https://discourse.julialang.org/u/johnbb)\
**Post date:** [April 18, 2022, 8:48pm UTC](https://discourse.julialang.org/t/flux-jl-dimensionmismatch-3-vs-4/79650/3 "2022-04-18T20:48:07Z")

</div>

It is the sample/batch dimension (no. of images). The dimensions are WHCN.
