added stop to break training loop

This commit is contained in:
Dhairya Gandhi 2018-08-17 17:46:13 +05:30
parent 23af487f98
commit 24a3bce495

View File

@ -1,5 +1,6 @@
using Juno using Juno
using Flux.Tracker: back! using Flux.Tracker: back!
include("../utls.jl")
runall(f) = f runall(f) = f
runall(fs::AbstractVector) = () -> foreach(call, fs) runall(fs::AbstractVector) = () -> foreach(call, fs)
@ -33,7 +34,12 @@ 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 = runall(cb) cb = try:
runall(cb)
catch e
if e isa StopException || rethrow()
@info "Stop Condition Met"
break
opt = runall(opt) opt = runall(opt)
@progress for d in data @progress for d in data
l = loss(d...) l = loss(d...)