Flux.jl/src/optimise/train.jl

18 lines
335 B
Julia
Raw Normal View History

2017-09-03 06:44:32 +00:00
using Juno
2017-08-31 16:36:18 +00:00
using Flux.Tracker: back!
2017-09-07 04:27:16 +00:00
tocb(f) = f
tocb(fs::AbstractVector) = () -> foreach(call, fs)
2017-09-07 04:29:55 +00:00
function train!(m, data, opt; cb = () -> ())
2017-09-07 04:27:16 +00:00
cb = tocb(cb)
2017-09-11 12:11:55 +00:00
@progress for x in data
2017-09-12 13:11:03 +00:00
l = m(x...)
2017-09-27 17:33:23 +00:00
isinf(l.data[]) && error("Loss is Inf")
isnan(l.data[]) && error("Loss is NaN")
2017-09-12 13:11:03 +00:00
back!(l)
2017-09-07 04:29:55 +00:00
opt()
cb()
2017-08-24 10:42:29 +00:00
end
end