JulesBelveze / time-series-autoencoder

PyTorch Dual-Attention LSTM-Autoencoder For Multivariate Time Series
Apache License 2.0
614 stars 63 forks source link

Tensors must have same number of dimensions: got 2 and 1 #8

Closed jawwada closed 3 years ago

jawwada commented 3 years ago

Traceback (most recent call last): File "main.py", line 101, in run(vars(args)) File "main.py", line 96, in run train(train_iter, test_iter, model, criterion, optimizer, config) File "/home/jupyter/time-series-autoencoder/train.py", line 44, in train output = model(feature.to(config["device"]), y_hist.to(config["device"])) File "/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 550, in call result = self.forward(*input, *kwargs) File "/home/jupyter/time-series-autoencoder/model.py", line 254, in forward outputs = self.decoder(encoder_output, y_hist.float()) File "/opt/conda/lib/python3.7/site-packages/torch/nn/modules/module.py", line 550, in call result = self.forward(input, **kwargs) File "/home/jupyter/time-series-autoencoder/model.py", line 222, in forward dim=1)) # (batch_size, out_size) RuntimeError: Tensors must have same number of dimensions: got 2 and 1

What could be the reason of the following error

Here are my args python main.py --batch-size 2 --output-size 2 --label-col T --input-att true --temporal-att true --seq-len 5 --hidden-size-encoder 5 --hidden-size-decoder 5 --reg-factor1 0.1 --reg-factor2 0.2 --reg1 true --reg2 true --denoising true --do-train true --do-eval true --data-path data.csv --output-dir output_dir

JulesBelveze commented 3 years ago

Hey @jawwada thanks for opening a new issue.

I suspect that y_history[:, t] is only one dimensional. You might need to unsqueeze one dimension by modifying it to something like:

y_tilde = self.fc(torch.cat((context.to(device), y_history[:, t].unsqueeze(1).to(device)),dim=1))  # (batch_size, out_size)

Let me know if that helps. Otherwise try to print the tensors shape after each layer.

jawwada commented 3 years ago

Hi JulesBelzeve, thanks a lot for the prompt answer. Your work indeed sounds amazing, although I have been unable to run it. I will get back to you. Where should I edit code and look to print tensor shape?

jawwada commented 3 years ago

This has finally started to run. I had to model my parameters exactly as in your config.py and run the program as python main.py without any arguments. Just giving the arguments in config.py where I wanted. May be I do not understand the model in full yet. Had to do a little bit of debugging. Thanks a lot for the help. I will connect with you over linkedin.

JulesBelveze commented 3 years ago

Glad to hear that you managed to have it working 😄

I definitely need to add some examples to the repo though!