modified training loop

This commit is contained in:
Dhairya Gandhi 2018-08-19 15:17:07 +05:30
parent 2aa057ec08
commit 8229c8e045

View File

@ -34,18 +34,22 @@ The callback can return `:stop` to interrupt the training loop.
Multiple optimisers and callbacks can be passed to `opt` and `cb` as arrays. Multiple optimisers and callbacks can be passed to `opt` and `cb` as arrays.
""" """
function train!(loss, data, opt; cb = () -> ()) function train!(loss, data, opt; cb = () -> ())
cb = try cb = runall(cb)
runall(cb)
catch ex
if ex isa StopException || rethrow(ex)
@info "Stop Condition Met"
return :stop
opt = runall(opt) opt = runall(opt)
@progress for d in data @progress for d in data
l = loss(d...) l = loss(d...)
@interrupts back!(l) @interrupts back!(l)
opt() opt()
cb() == :stop && break try
cb()
catch ex
if ex isa StopException
@info "Stop condition met"
break
else
rethrow(ex)
end
end end
end end