MCPcopy Create free account
hub / github.com/RolnickLab/climart / TestingScheduleCallback

Class TestingScheduleCallback

climart/utils/callbacks.py:6–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4
5
6class TestingScheduleCallback:
7 def __init__(self,
8 start_epoch: int = 1,
9 test_at_most_every_n_epochs: int = 10,
10 test_at_least_every_n_epochs: int = 20,
11 test_on_new_best_validation: bool = True,
12 ignore_first_n_epochs: int = 5,
13 ):
14 self.test_at_most_every_n_epochs = test_at_most_every_n_epochs
15 self.test_at_least_every_n_epochs = test_at_least_every_n_epochs
16 self.test_on_new_best_validation = test_on_new_best_validation
17 self.untested_epochs = 1
18 self.cur_epoch = start_epoch
19 self.ignore_first_n_epochs = ignore_first_n_epochs
20
21 def __call__(self, is_new_best_val_model: bool = False) -> bool:
22 do_test = False
23 if self.cur_epoch <= self.ignore_first_n_epochs:
24 do_test = False
25 elif self.untested_epochs >= self.test_at_least_every_n_epochs:
26 do_test = True
27 elif self.test_on_new_best_validation and is_new_best_val_model:
28 if self.untested_epochs < self.test_at_most_every_n_epochs:
29 do_test = False
30 else:
31 do_test = True
32
33 self.cur_epoch += 1
34 if do_test:
35 self.untested_epochs = 1
36 else:
37 self.untested_epochs += 1
38 return do_test
39
40
41class PredictionPostProcessCallback:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected