Created
March 29, 2019 05:28
-
-
Save edwardeasling/e2107e74e3eacdc7673c97023ac1219b to your computer and use it in GitHub Desktop.
BP1 - 03
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CallbackHandler(): | |
def __init__(self,cbs=None): | |
self.cbs = cbs if cbs else [] | |
def begin_fit(self, learn): | |
self.learn,self.in_train = learn,True | |
learn.stop = False | |
res = True | |
for cb in self.cbs: res = res and cb.begin_fit(learn) | |
return res | |
def after_fit(self): | |
res = not self.in_train | |
for cb in self.cbs: res = res and cb.after_fit() | |
return res | |
def begin_epoch(self, epoch): | |
learn.model.train() | |
self.in_train=True | |
res = True | |
for cb in self.cbs: res = res and cb.begin_epoch(epoch) | |
return res | |
def begin_validate(self): | |
self.learn.model.eval() | |
self.in_train=False | |
res = True | |
for cb in self.cbs: res = res and cb.begin_validate() | |
return res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment