jdb78 / pytorch-forecasting

Time series forecasting with PyTorch
https://pytorch-forecasting.readthedocs.io/
MIT License
3.87k stars 611 forks source link

IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1) #269

Closed jiryang closed 3 years ago

jiryang commented 3 years ago

Expected behavior

Getting baseline prediction result (using SMAPE) of Nbeats sample code shows the below error: Traceback (most recent call last): File "welt_forecast_nbeats.py", line 90, in print(SMAPE()(baseline_predictions, actuals)) File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 744, in _call_impl result = self.forward(*input, kwargs) File "/usr/local/lib/python3.6/dist-packages/pytorch_lightning/metrics/metric.py", line 153, in forward self.update(*args, *kwargs) File "/usr/local/lib/python3.6/dist-packages/pytorch_lightning/metrics/metric.py", line 199, in wrapped_func return update(args, kwargs) File "/usr/local/lib/python3.6/dist-packages/pytorch_forecasting/metrics.py", line 308, in update target, lengths = unpack_sequence(target) File "/usr/local/lib/python3.6/dist-packages/pytorch_forecasting/utils.py", line 232, in unpack_sequence lengths = torch.ones(sequence.size(0), device=sequence.device, dtype=torch.long) * sequence.size(1) IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)

Code to reproduce the problem

calculate baseline absolute error

actuals = torch.cat([y[0] for x, y in iter(val_dataloader)]) baseline_predictions = Baseline().predict(val_dataloader) SMAPE()(baseline_predictions, actuals)

jdb78 commented 3 years ago

You need to update pytorch forecasting. Should do the trick.