Hi, I am doing a machine learning using gradient descend
# I have a set of data, called samples
# I have two models: model1 and model2
global par = Flux.params(model1, model2) #wrap them in params
gs = gradient(par) do
global l1 = mean(Flux.mse(model(sample),true1)) for sample in samples)
global l2 = 0
global count = 0
global allLoss = 0
for sample in samples
nbSec = count ÷ 6
true2 = label[nbSec+1,:,1]
global l2 += Flux.mse(model2(sample),true2)
count += 1
end
l2 = l2 / length(samples)
allLoss = l1 + l2
println("l: ",l1) # print 1.6994402448439135e15
println("l2: ",l2) # print 3.004242981094107e17
println("allLoss: ", allLoss) # print 3.021237383542546e17
end
Flux.update!(opt, par, gs)
As you can see, the output of l1 and l2 are two float64 numbers. They are scale. However, when I use Flux.update, it gives me error:
ERROR: LoadError: Output should be scalar; gradients are not defined for output nothing
I wonder why I have this mistake