Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
jantic
GitHub Repository: jantic/deoldify
Path: blob/master/fastai/callbacks/misc.py
781 views
1
" Miscellaneous callbacks "
2
3
from fastai.callback import Callback
4
5
class StopAfterNBatches(Callback):
6
"Stop training after n batches of the first epoch."
7
def __init__(self, n_batches:int=2):
8
self.stop,self.n_batches = False,n_batches-1 # iteration starts from 0
9
10
def on_batch_end(self, iteration, **kwargs):
11
if iteration == self.n_batches:
12
return {'stop_epoch': True, 'stop_training': True, 'skip_validate': True}
13
14