Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
add model saving callback
Browse files Browse the repository at this point in the history
  • Loading branch information
Steffen-Wolf committed Aug 9, 2019
1 parent 90d4b9b commit bd63892
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions inferno/trainers/callbacks/scheduling.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,3 +393,19 @@ def end_of_training_iteration(self, **_):
self.decay(global_factor)


class SaveModelRegularly(Callback):
"""saves the network weights in regular intervals"""

def __init__(self, frequency):
super().__init__()
self._save_every = Frequency.build_from(frequency)

@property
def save_now(self):
return self._save_every.match(iteration_count=self.trainer.iteration_count,
epoch_count=self.trainer.epoch_count,
persistent=True, match_zero=True)

def end_of_training_iteration(self, **_):
if self.save_now:
self.trainer.save_model()

0 comments on commit bd63892

Please sign in to comment.