Flux.jl DimensionMismatch(3 vs 4)

I am using conv network model from this repo
And when i try to use my image i am getting this error:

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:

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

Model:

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

So i fixed error by reshaping my array like:

reshape(mat, (28, 28, 1, :))

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

1 Like

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

1 Like