I cannot understand Flux.testmode!
and Flux.trainmode!
well.
When I use Flux.testmode(), I found trainloss is lower exactly,
For example as follows:
if using Flux.testmode()
train_pro_loss is lower much than valid_pro_loss, or not, train_pro_loss is near valid_pro_loss when train data number is equal to valid data.
lossfun = () -> push!(losses, [cal_loss(train.data...)])
losses=[]
train_pro_loss, valid_pro_loss=[],[]
opt, θ = Adam(0.01), Flux.params(model)
for _ = 1:num_epochs
for (X, y) in train
gradients = Flux.gradient(θ) do
cal_loss(X, y)
end
Flux.update!(opt, θ, gradients)
end
Flux.testmode!(model)
lossfun()
push!(train_pro_loss, cal_loss(train.data...))
push!(valid_pro_loss, cal_loss(valid.data...))
end