| 4 | |
| 5 | |
| 6 | class StateCallback(Callback): |
| 7 | |
| 8 | def __init__(self): |
| 9 | pass |
| 10 | |
| 11 | def after_forward_pass(self, phase, loss, loss_pos, loss_dir, loss_curv, **kwargs): |
| 12 | phase.iter_nr+=1 |
| 13 | phase.samples_processed_this_epoch+=1 |
| 14 | phase.loss_acum_per_epoch+=loss |
| 15 | phase.loss_pos_acum_per_epoch+=loss_pos |
| 16 | phase.loss_dir_acum_per_epoch+=loss_dir |
| 17 | phase.loss_curv_acum_per_epoch+=loss_curv |
| 18 | |
| 19 | |
| 20 | def epoch_started(self, phase, **kwargs): |
| 21 | phase.loss_acum_per_epoch=0.0 |
| 22 | phase.loss_pos_acum_per_epoch=0.0 |
| 23 | phase.loss_dir_acum_per_epoch=0.0 |
| 24 | phase.loss_curv_acum_per_epoch=0.0 |
| 25 | |
| 26 | def epoch_ended(self, phase, **kwargs): |
| 27 | |
| 28 | phase.epoch_nr+=1 |
| 29 | |
| 30 | def phase_started(self, phase, **kwargs): |
| 31 | phase.samples_processed_this_epoch=0 |
| 32 | |
| 33 | def phase_ended(self, phase, model, hyperparams, experiment_name, output_training_path, **kwargs): |
| 34 | |
| 35 | if (phase.epoch_nr%hyperparams.save_checkpoint_every_x_epoch==0) and hyperparams.save_checkpoint and phase.grad: |
| 36 | model.save(output_training_path, experiment_name, hyperparams, phase.epoch_nr) |
| 37 | |
| 38 | |