(self, metadata)
Store checkpoint if metric is in its all time low.
Store checkpoint if metric is in its all time low.
Store checkpoint if metric is in its all time low .
def on_epoch_end(self, metadata):
        """Store checkpoint if metric is in its all time low."""
        epoch = metadata['epoch']
        stats = self.run.history.metrics_per_epoch(epoch)

        if not (len(stats['lookback'].unique()) == 1 and len(stats['model'].unique()) == 1):
            raise ValueError('ModelCheckpointCallback needs to have a single lookback and model')  # pragma: no cover

        stats_formatted = stats.groupby(['dataloader', 'metric'])['value'].mean().unstack(-1)
        current_metric = stats_formatted.loc[self.dataloader_name, self.metric_name]

        if current_metric < self.min:
            self.min = current_metric

            checkpoint_path = self.folder_path / 'model_{:02d}__{:.4f}.pth'.format(epoch, current_metric)
            torch.save(self.run.network, str(checkpoint_path))

            if self.verbose:
                print('Checkpointed {}'.format(checkpoint_path))
def on_epoch_end ( self , metadata ) : epoch = metadata [ 'epoch' ] stats = self . run . history . metrics_per_epoch ( epoch ) if not ( len ( stats [ 'lookback' ] . unique ( ) ) == 1 and len ( stats [ 'model' ] . unique ( ) ) == 1 ) : raise ValueError ( 'ModelCheckpointCallback needs to have a single lookback and model' ) # pragma: no cover stats_formatted = stats . groupby ( [ 'dataloader' , 'metric' ] ) [ 'value' ] . mean ( ) . unstack ( - 1 ) current_metric = stats_formatted . loc [ self . dataloader_name , self . metric_name ] if current_metric < self . min : self . min = current_metric checkpoint_path = self . folder_path / 'model_{:02d}__{:.4f}.pth' . format ( epoch , current_metric ) torch . save ( self . run . network , str ( checkpoint_path ) ) if self . verbose : print ( 'Checkpointed {}' . format ( checkpoint_path ) )