[BUG] ValueError: __len__() should return >= 0
See original GitHub issueDescribe the bug
When using val_series
with RNNModel
, I am getting an error. When running the exact same code with NBEATS
, it works. The error occurs unless my val_series
has at least a lengh of 25
. I have tried training series of different length and different input_chunk_length
and output_chunk_length
without success. I at least think this is not expected.
To Reproduce This produces an error:
model_RNN = RNNModel(input_chunk_length=10, output_chunk_length=1, n_epochs=250,
batch_size=1024, torch_device_str="cuda:0")
model_RNN.fit(series=ts_list_train, val_series=ts_list_val
)
This does not produce an error:
model_NBEATS = NBEATSModel(input_chunk_length=10, output_chunk_length=1, n_epochs=250,
batch_size=1024, torch_device_str="cuda:0")
model_NBEATS.fit(series=ts_list_train, val_series=ts_list_val
)
Additional context Traceback below:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
/tmp/ipykernel_12641/796312022.py in <module>
1 model_RNN = RNNModel(input_chunk_length=10, output_chunk_length=1, n_epochs=250,
2 batch_size=1024, torch_device_str="cuda:0")
----> 3 model_RNN.fit(series=ts_list_train, verbose=True, val_series=ts_list_val
4 )
~/darts/lib/python3.8/site-packages/darts/utils/torch.py in decorator(self, *args, **kwargs)
63 with fork_rng():
64 manual_seed(self._random_instance.randint(0, high=MAX_TORCH_SEED_VALUE))
---> 65 return decorated(self, *args, **kwargs)
66 return decorator
~/darts/lib/python3.8/site-packages/darts/models/forecasting/torch_forecasting_model.py in fit(self, series, past_covariates, future_covariates, val_series, val_past_covariates, val_future_covariates, verbose, epochs)
429 logger.info('Train dataset contains {} samples.'.format(len(train_dataset)))
430
--> 431 self.fit_from_dataset(train_dataset, val_dataset, verbose, epochs)
432
433 @random_method
~/darts/lib/python3.8/site-packages/darts/utils/torch.py in decorator(self, *args, **kwargs)
63 with fork_rng():
64 manual_seed(self._random_instance.randint(0, high=MAX_TORCH_SEED_VALUE))
---> 65 return decorated(self, *args, **kwargs)
66 return decorator
~/darts/lib/python3.8/site-packages/darts/models/forecasting/torch_forecasting_model.py in fit_from_dataset(self, train_dataset, val_dataset, verbose, epochs)
465 'The provided training time series dataset is too short for obtaining even one training point.',
466 logger)
--> 467 raise_if(val_dataset is not None and len(val_dataset) == 0,
468 'The provided validation time series dataset is too short for obtaining even one training point.',
469 logger)
~/darts/lib/python3.8/site-packages/darts/utils/data/shifted_dataset.py in __len__(self)
212
213 def __len__(self):
--> 214 return len(self.ds_past)
215
216 def __getitem__(self, idx) -> Tuple[np.ndarray, Optional[np.ndarray], Optional[np.ndarray], np.ndarray]:
ValueError: __len__() should return >= 0
Issue Analytics
- State:
- Created 2 years ago
- Comments:9 (5 by maintainers)
Top Results From Across the Web
ValueError: __len__() should return >= 0 - Stack Overflow
I want to make a transformer model by darts package by the code below : my_model = TransformerModel( input_chunk_length=12, ...
Read more >ERROR: __len__() should return >= 0 on liveFeed
Hello everyone. I need help I am working on implementing a new data feed / live broker. I have taken Oanda as a...
Read more >Avoid raising OverflowError in len() when __len__() returns ...
msg289779 ‑ (view) Author: Serhiy Storchaka (serhiy.storchaka) * Date: 2017‑03‑17 19:52
msg289782 ‑ (view) Author: Barry A. Warsaw (barry) * Date: 2017‑03‑17 20:28
msg290109 ‑...
Read more >Python - Check if a list is empty or not - GeeksforGeeks
Method 1: Check the empty list using the len() With Comparison ... return 0 ... If the list contains one 0, then the...
Read more >30. Errors and Exception Handling | Python Tutorial
If we use a input(), the input will be a string, which we have to cast ... return age except ValueError as e:...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @JulianNyarko and thanks for writing.
RNNModel
takes an optional parametertraining_length
which defaults to 24.From our RNNModel docs on
training_length
(see here):ShiftedDataset
additionally shifts the data by +1 time step. So in total, the length of yourval_series
TimeSeries should be >= 25.I agree that it might be a bit hard to identify what is causing this Error. @hrzn, @pennfranc couldn’t we check for correct input at the beginning of fit?
The error message was improved in 0.21.0