I'm getting this error:
DimensionMismatch("second dimension of A, 1, does not match length of x, 20")
for the following code. I'm trying to train a model on some sample data. I'm using the Flux machine learning library in Julia.
I've checked my dimensions and they seem right to me. What is the problem?
using Flux
using Flux: mse
data = [(i,i) for i in 1:20]
x = [i for i in 1:20]
y = [i for i in 1:20]
m = Chain(
Dense(1, 10, relu),
Dense(10, 1),
softmax)
opt = ADAM(params(m))
loss(x, y) = mse(m(x), y)
evalcb = () -> @show(loss(x, y))
accuracy(x, y) = mean(argmax(m(x)) .== argmax(y))
#this line gives the error
Flux.train!(loss, data, opt,cb = throttle(evalcb, 10))
Your first dense layer has a weight matrix whose size is
10x1. You can check it as follows:So, your data should be size of
1x20so that you can multiply it with the weights in the chain.