Flux.jl/src/optimise/train.jl
2017-09-27 18:33:23 +01:00

18 lines
335 B
Julia

using Juno
using Flux.Tracker: back!
tocb(f) = f
tocb(fs::AbstractVector) = () -> foreach(call, fs)
function train!(m, data, opt; cb = () -> ())
cb = tocb(cb)
@progress for x in data
l = m(x...)
isinf(l.data[]) && error("Loss is Inf")
isnan(l.data[]) && error("Loss is NaN")
back!(l)
opt()
cb()
end
end