zalandoresearch/pytorch-ts

TimeGrad Error: "target" does not have the requireddimension

Closed this issue · 0 comments

Hi,

I am using the example in the readme page and using TimeGradEstimator:

url = "https://raw.githubusercontent.com/numenta/NAB/master/data/realTweets/Twitter_volume_AMZN.csv"
df = pd.read_csv(url, header=0, index_col=0, parse_dates=True)
training_data = ListDataset(
    [{"start": df.index[0], "target": df.value[:"2015-04-05 00:00:00"]}],
    freq = "5min"
)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

estimator = TimeGradEstimator(
    target_dim=1,
    prediction_length=12,
    cell_type='GRU',
    input_size=19,
    freq= "5min",
    loss_type='l2',
    scaling=True,
    diff_steps=100,
    beta_end=0.1,
    beta_schedule="linear",
    trainer=Trainer(device=device,
                    epochs=20,
                    learning_rate=1e-3,
                    num_batches_per_epoch=100,
                    batch_size=64,)
)

predictor = estimator.train(training_data, , num_workers=4)

and got this error

GluonTSDataError                          Traceback (most recent call last)
Cell In[46], line 27
      3 training_data = ListDataset(
      4     [{"start": df.index[0], "target": df.value[:"2015-04-05 00:00:00"]}],
      5     freq = "5min"
      6 )
      8 estimator = TimeGradEstimator(
      9     target_dim=1,
     10     prediction_length=prediction_length,
   (...)
     24                     batch_size=64,)
     25 )
---> 27 predictor = estimator.train(training_data, prefetch_factor=None)

File ~/projects/pytorch-ts/pts/model/estimator.py:179, in PyTorchEstimator.train(self, training_data, validation_data, num_workers, prefetch_factor, shuffle_buffer_length, cache_data, **kwargs)
    169 def train(
    170     self,
    171     training_data: Dataset,
   (...)
    177     **kwargs,
    178 ) -> PyTorchPredictor:
--> 179     return self.train_model(
    180         training_data,
    181         validation_data,
    182         num_workers=num_workers,
    183         prefetch_factor=prefetch_factor,
    184         shuffle_buffer_length=shuffle_buffer_length,
    185         cache_data=cache_data,
    186         **kwargs,
    187     ).predictor

File ~/projects/pytorch-ts/pts/model/estimator.py:151, in PyTorchEstimator.train_model(self, training_data, validation_data, num_workers, prefetch_factor, shuffle_buffer_length, cache_data, **kwargs)
    133     validation_iter_dataset = TransformedIterableDataset(
    134         dataset=validation_data,
    135         transform=transformation
   (...)
    139         cache_data=cache_data,
    140     )
    141     validation_data_loader = DataLoader(
    142         validation_iter_dataset,
    143         batch_size=self.trainer.batch_size,
   (...)
    148         **kwargs,
    149     )
--> 151 self.trainer(
    152     net=trained_net,
    153     train_iter=training_data_loader,
    154     validation_iter=validation_data_loader,
    155 )
    157 return TrainOutput(
    158     transformation=transformation,
    159     trained_net=trained_net,
   (...)
    162     ),
    163 )

File ~/projects/pytorch-ts/pts/trainer.py:63, in Trainer.__call__(self, net, train_iter, validation_iter)
     61 # training loop
     62 with tqdm(train_iter, total=total) as it:
---> 63     for batch_no, data_entry in enumerate(it, start=1):
     64         optimizer.zero_grad()
     66         inputs = [v.to(self.device) for v in data_entry.values()]

File ~/opt/anaconda3/envs/torch111-difusco/lib/python3.10/site-packages/tqdm/notebook.py:249, in tqdm_notebook.__iter__(self)
    247 try:
    248     it = super(tqdm_notebook, self).__iter__()
--> 249     for obj in it:
    250         # return super(tqdm...) will not catch exception
    251         yield obj
    252 # NB: except ... [ as ...] breaks IPython async KeyboardInterrupt

File ~/opt/anaconda3/envs/torch111-difusco/lib/python3.10/site-packages/tqdm/std.py:1182, in tqdm.__iter__(self)
   1179 time = self._time
   1181 try:
-> 1182     for obj in iterable:
   1183         yield obj
   1184         # Update and possibly print the progressbar.
   1185         # Note: does not call self.update(1) for speed optimisation.

File ~/opt/anaconda3/envs/torch111-difusco/lib/python3.10/site-packages/torch/utils/data/dataloader.py:631, in _BaseDataLoaderIter.__next__(self)
    628 if self._sampler_iter is None:
    629     # TODO(https://github.com/pytorch/pytorch/issues/76750)
    630     self._reset()  # type: ignore[call-arg]
--> 631 data = self._next_data()
    632 self._num_yielded += 1
    633 if self._dataset_kind == _DatasetKind.Iterable and \
    634         self._IterableDataset_len_called is not None and \
    635         self._num_yielded > self._IterableDataset_len_called:

File ~/opt/anaconda3/envs/torch111-difusco/lib/python3.10/site-packages/torch/utils/data/dataloader.py:675, in _SingleProcessDataLoaderIter._next_data(self)
    673 def _next_data(self):
    674     index = self._next_index()  # may raise StopIteration
--> 675     data = self._dataset_fetcher.fetch(index)  # may raise StopIteration
    676     if self._pin_memory:
    677         data = _utils.pin_memory.pin_memory(data, self._pin_memory_device)

File ~/opt/anaconda3/envs/torch111-difusco/lib/python3.10/site-packages/torch/utils/data/_utils/fetch.py:32, in _IterableDatasetFetcher.fetch(self, possibly_batched_index)
     30 for _ in possibly_batched_index:
     31     try:
---> 32         data.append(next(self.dataset_iter))
     33     except StopIteration:
     34         self.ended = True

File ~/opt/anaconda3/envs/torch111-difusco/lib/python3.10/site-packages/gluonts/transform/_base.py:111, in TransformedDataset.__iter__(self)
    110 def __iter__(self) -> Iterator[DataEntry]:
--> 111     yield from self.transformation(
    112         self.base_dataset, is_train=self.is_train
    113     )

File ~/opt/anaconda3/envs/torch111-difusco/lib/python3.10/site-packages/gluonts/transform/_base.py:132, in MapTransformation.__call__(self, data_it, is_train)
    129 def __call__(
    130     self, data_it: Iterable[DataEntry], is_train: bool
    131 ) -> Iterator:
--> 132     for data_entry in data_it:
    133         try:
    134             yield self.map_transform(data_entry.copy(), is_train)

File ~/opt/anaconda3/envs/torch111-difusco/lib/python3.10/site-packages/gluonts/transform/_base.py:132, in MapTransformation.__call__(self, data_it, is_train)
    129 def __call__(
    130     self, data_it: Iterable[DataEntry], is_train: bool
    131 ) -> Iterator:
--> 132     for data_entry in data_it:
    133         try:
    134             yield self.map_transform(data_entry.copy(), is_train)

File ~/opt/anaconda3/envs/torch111-difusco/lib/python3.10/site-packages/gluonts/transform/_base.py:186, in FlatMapTransformation.__call__(self, data_it, is_train)
    182 def __call__(
    183     self, data_it: Iterable[DataEntry], is_train: bool
    184 ) -> Iterator:
    185     num_idle_transforms = 0
--> 186     for data_entry in data_it:
    187         num_idle_transforms += 1
    188         for result in self.flatmap_transform(data_entry.copy(), is_train):

File ~/opt/anaconda3/envs/torch111-difusco/lib/python3.10/site-packages/gluonts/transform/_base.py:132, in MapTransformation.__call__(self, data_it, is_train)
    129 def __call__(
    130     self, data_it: Iterable[DataEntry], is_train: bool
    131 ) -> Iterator:
--> 132     for data_entry in data_it:
    133         try:
    134             yield self.map_transform(data_entry.copy(), is_train)

File ~/opt/anaconda3/envs/torch111-difusco/lib/python3.10/site-packages/gluonts/transform/_base.py:132, in MapTransformation.__call__(self, data_it, is_train)
    129 def __call__(
    130     self, data_it: Iterable[DataEntry], is_train: bool
    131 ) -> Iterator:
--> 132     for data_entry in data_it:
    133         try:
    134             yield self.map_transform(data_entry.copy(), is_train)

    [... skipping similar frames: MapTransformation.__call__ at line 132 (4 times)]

File ~/opt/anaconda3/envs/torch111-difusco/lib/python3.10/site-packages/gluonts/transform/_base.py:132, in MapTransformation.__call__(self, data_it, is_train)
    129 def __call__(
    130     self, data_it: Iterable[DataEntry], is_train: bool
    131 ) -> Iterator:
--> 132     for data_entry in data_it:
    133         try:
    134             yield self.map_transform(data_entry.copy(), is_train)

File ~/opt/anaconda3/envs/torch111-difusco/lib/python3.10/site-packages/gluonts/transform/_base.py:136, in MapTransformation.__call__(self, data_it, is_train)
    134     yield self.map_transform(data_entry.copy(), is_train)
    135 except Exception as e:
--> 136     raise e

File ~/opt/anaconda3/envs/torch111-difusco/lib/python3.10/site-packages/gluonts/transform/_base.py:134, in MapTransformation.__call__(self, data_it, is_train)
    132 for data_entry in data_it:
    133     try:
--> 134         yield self.map_transform(data_entry.copy(), is_train)
    135     except Exception as e:
    136         raise e

File ~/opt/anaconda3/envs/torch111-difusco/lib/python3.10/site-packages/gluonts/transform/_base.py:149, in SimpleTransformation.map_transform(self, data, is_train)
    148 def map_transform(self, data: DataEntry, is_train: bool) -> DataEntry:
--> 149     return self.transform(data)

File ~/opt/anaconda3/envs/torch111-difusco/lib/python3.10/site-packages/gluonts/transform/convert.py:139, in AsNumpyArray.transform(self, data)
    136 def transform(self, data: DataEntry) -> DataEntry:
    137     value = np.asarray(data[self.field], dtype=self.dtype)
--> 139     assert_data_error(
    140         value.ndim == self.expected_ndim,
    141         'Input for field "{self.field}" does not have the required'
    142         "dimension (field: {self.field}, ndim observed: {value.ndim}, "
    143         "expected ndim: {self.expected_ndim})",
    144         value=value,
    145         self=self,
    146     )
    147     data[self.field] = value
    148     return data

File ~/opt/anaconda3/envs/torch111-difusco/lib/python3.10/site-packages/gluonts/exceptions.py:116, in assert_data_error(condition, message, *args, **kwargs)
     98 def assert_data_error(condition: Any, message: str, *args, **kwargs) -> None:
     99     """
    100     Delegates to :func:`assert_gluonts` with a fixed ``exception_class`` value
    101     of ``GluonTSDataError``.
   (...)
    114         exception message.
    115     """
--> 116     assert_gluonts(GluonTSDataError, condition, message, *args, **kwargs)

File ~/opt/anaconda3/envs/torch111-difusco/lib/python3.10/site-packages/gluonts/exceptions.py:95, in assert_gluonts(exception_class, condition, message, *args, **kwargs)
     74 """
     75 If the given ``condition`` is ``False``, raises an exception of type
     76 ``exception_class`` with a message formatted from the ``message`` pattern
   (...)
     92     exception message.
     93 """
     94 if not condition:
---> 95     raise exception_class(message.format(*args, **kwargs))

GluonTSDataError: Input for field "target" does not have the requireddimension (field: target, ndim observed: 1, expected ndim: 2)