MCPcopy Create free account
hub / github.com/DeepGraphLearning/S3F / train_and_validate

Function train_and_validate

script/pretrain.py:18–38  ·  view source on GitHub ↗
(cfg, solver)

Source from the content-addressed store, hash-verified

16
17
18def train_and_validate(cfg, solver):
19 if cfg.train.num_epoch == 0:
20 return
21
22 step = math.ceil(cfg.train.num_epoch / 50)
23 best_result = float("-inf")
24 best_epoch = -1
25
26 for i in range(0, cfg.train.num_epoch, step):
27 kwargs = cfg.train.copy()
28 kwargs["num_epoch"] = min(step, cfg.train.num_epoch - i)
29 solver.train(**kwargs)
30 solver.save("model_epoch_%d.pth" % solver.epoch)
31 metric = solver.evaluate("valid")
32 result = metric[cfg.metric]
33 if result > best_result:
34 best_result = result
35 best_epoch = solver.epoch
36
37 solver.load("model_epoch_%d.pth" % best_epoch)
38 return solver
39
40
41if __name__ == "__main__":

Callers 1

pretrain.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected