(self, metadata)
Compute metrics and log them into the history object.
Compute metrics and log them into the history object.
Compute metrics and log them into the history object .
def on_epoch_end(self, metadata):
        """Compute metrics and log them into the history object."""
        epoch = metadata.get('epoch')
        model = self.run.network
        model.eval()

        if epoch % self.freq == 0:
            with torch.no_grad():
                for dl_name, dl in self.run.val_dataloaders.items():
                    for batch, (X_batch, y_batch, timestamps_batch, _) in enumerate(dl):
                        X_batch = X_batch.to(self.run.device).to(self.run.dtype)
                        y_batch = y_batch.to(self.run.device).to(self.run.dtype)

                        lookbacks = []
                        if self.lookbacks is None:
                            lookbacks.append(X_batch.shape[2])
                        else:
                            lookbacks = self.lookbacks

                        for lb in lookbacks:
                            weights = model(X_batch[:, :, -lb:, :])

                            for metric_name, metric in self.run.metrics.items():
                                metric_per_s = metric(weights, y_batch).detach().cpu().numpy()

                                for metric_value, ts in zip(metric_per_s, timestamps_batch):
                                    self.run.history.add_entry(timestamp=ts,
                                                               model='network',
                                                               epoch=epoch,
                                                               batch=batch,
                                                               lookback=lb,
                                                               dataloader=dl_name,
                                                               metric=metric_name,
                                                               value=metric_value)
def on_epoch_end ( self , metadata ) : epoch = metadata . get ( 'epoch' ) model = self . run . network model . eval ( ) if epoch % self . freq == 0 : with torch . no_grad ( ) : for dl_name , dl in self . run . val_dataloaders . items ( ) : for batch , ( X_batch , y_batch , timestamps_batch , _ ) in enumerate ( dl ) : X_batch = X_batch . to ( self . run . device ) . to ( self . run . dtype ) y_batch = y_batch . to ( self . run . device ) . to ( self . run . dtype ) lookbacks = [ ] if self . lookbacks is None : lookbacks . append ( X_batch . shape [ 2 ] ) else : lookbacks = self . lookbacks for lb in lookbacks : weights = model ( X_batch [ : , : , - lb : , : ] ) for metric_name , metric in self . run . metrics . items ( ) : metric_per_s = metric ( weights , y_batch ) . detach ( ) . cpu ( ) . numpy ( ) for metric_value , ts in zip ( metric_per_s , timestamps_batch ) : self . run . history . add_entry ( timestamp = ts , model = 'network' , epoch = epoch , batch = batch , lookback = lb , dataloader = dl_name , metric = metric_name , value = metric_value )