Open clianga opened 2 years ago
I've encountered the same RuntimeError with shape mismatch when using AggregationMetric(some_metric)
as loss.
To my understanding, it was connected with the predictions and actuals shape mismatch:
Can you check whether original MAE()
works for you?
if no - as a quick workaround I suggest adding in loss
method last axis averaging:
def loss(self, y_pred, target):
y_pred = self.to_prediction(y_pred)
if y_pred.ndim == 3:
# maybe some other checks
y_pred = y_pred.mean(axis=-1)
loss = (y_pred - target).abs()
return loss
Hope it will help you to solve the issue
Expected behavior
I'm trying to apply a weight to each sample (and losses) to get rid of the covid effect. Say I have 100 time series from 2016 to 2022, and I want the model not update parameters from 2020 Mar 1st to 2020 July 30th. Hence I created a weight in my panda DataFrame, and let the weight = 0 when time is between 2020 Mar 1st to 2020 July 30th, and 1 elsewhere, for all 100 time series. The dataset creating code is here:
I check the tensor size for training and validation, it matches. Then I run code
to create a model and it went through without error. However when I try to train the model using code:
It produces an error
~/anaconda3/envs/pytorch_latest_p36/lib/python3.6/site-packages/pytorch_forecasting/metrics.py in update(self, y_pred, target, encoder_target, encoder_lengths) 854 # weight samples 855 if weight is not None: --> 856 losses = losses * weight.unsqueeze(-1) 857 858 self._update_losses_and_lengths(losses, lengths)
RuntimeError: The size of tensor a (119) must match the size of tensor b (60) at non-singleton dimension 1
Can you tell me how to fix it? Or is there a way to apply weight to the losses (for different samples different weight is applied). Thank you!