PaddlePaddle / PaddleTS

Awesome Easy-to-Use Deep Time Series Modeling based on PaddlePaddle, including comprehensive functionality modules like TSDataset, Analysis, Transform, Models, AutoTS, and Ensemble, etc., supporting versatile tasks like time series forecasting, representation learning, and anomaly detection, etc., featured with quick tracking of SOTA deep models.
Apache License 2.0
487 stars 118 forks source link

静态变量的使用 #472

Closed IgnoranceSmile closed 8 months ago

IgnoranceSmile commented 8 months ago

有人使用静态变量并成功运行过么 我的代码如下: import pandas as pd from paddlets import TSDataset

x = np.linspace(-np.pi, np.pi, 200) sinx = np.sin(x) * 4 + np.random.randn(200)

df = pd.DataFrame( { 'time_col': pd.date_range('2022-01-01', periods=200, freq='1h'), 'value': sinx, 'known_cov_1': sinx + 4, 'known_cov_2': sinx + 5, 'observed_cov': sinx + 8, 'static_cov': [1 for i in range(200)], } ) target_cov_dataset = TSDataset.load_from_dataframe( df, time_col='time_col', target_cols='value', known_cov_cols=['known_cov_1', 'known_cov_2'], observed_cov_cols='observed_cov', static_cov_cols='static_cov', freq='1h' )

temporal_fusion_transformer = TFTModel( in_chunk_len = in_chunk_len, out_chunk_len = out_chunk_len, max_epochs=800, patience=100 )

temporal_fusion_transformer.fit(target_cov_dataset) 报错:

ValueError Traceback (most recent call last) /tmp/ipykernel_43360/875506061.py in 32 ) 33 ---> 34 temporal_fusion_transformer.fit(target_cov_dataset)

/usr/local/lib/python3.7/dist-packages/paddlets/models/forecasting/dl/paddle_base_impl.py in fit(self, train_tsdataset, valid_tsdataset) 344 self._check_multi_tsdataset(valid_tsdataset) 345 train_dataloader, valid_dataloaders = self._init_fit_dataloaders(train_tsdataset, valid_tsdataset) --> 346 self._fit(train_dataloader, valid_dataloaders) 347 348 def _fit(

/usr/local/lib/python3.7/dist-packages/paddlets/models/forecasting/dl/paddle_base_impl.py in _fit(self, train_dataloader, valid_dataloaders) 370 # Call the on_epoch_begin method of each callback before the epoch starts. 371 self._callback_container.on_epoch_begin(epoch_idx) --> 372 self._train_epoch(train_dataloader) 373 374 # Predict for each eval set.

/usr/local/lib/python3.7/dist-packages/paddlets/models/forecasting/dl/paddle_base_impl.py in _train_epoch(self, train_loader) 438 self._callback_container.on_batch_begin(batch_idx) 439 X, y = self._prepare_X_y(data) --> 440 batch_logs = self._train_batch(X, y) ... 208 helper = LayerHelper('embedding', **locals())

ValueError: (InvalidArgument) Variable value (input) of OP(fluid.layers.embedding) expected >= 0 and < 1, but got 1. Please check input value. [Hint: Expected ids[i] < row_number, but received ids[i]:1 >= row_number:1.] (at /paddle/paddle/phi/kernels/cpu/embedding_kernel.cc:63) [operator < lookup_table_v2 > error]

Sunting78 commented 8 months ago

您好,麻烦提供下具体环境,我们复现跟进。

IgnoranceSmile commented 8 months ago

使用官方最新的Docker运行的 语言名称及版本:Python 3.7.13 依赖库及其版本:paddlepaddle 2.3.2 paddlets 1.1.0

测试后发现静态协变量不能为int类型,修改为float类型后可以正常运行

Sunting78 commented 8 months ago

是的,已解决,问题关闭。