chickenbestlover / RNN-Time-series-Anomaly-Detection

RNN based Time-series Anomaly detector model implemented in Pytorch.
Apache License 2.0
1.17k stars 316 forks source link

RuntimeError: view size is not compatible with input tensor's size and stride #38

Closed lhduc94 closed 4 years ago

lhduc94 commented 4 years ago

Thank you for your repo. When I run the script python 1_train_predictor.py --data nyc_taxi --filename nyc_taxi.pkl . It raises an Error

Traceback (most recent call last):
  File "1_train_predictor.py", line 320, in <module>
    train(args,model,train_dataset,epoch)
  File "1_train_predictor.py", line 228, in train
    loss1 = criterion(outSeq1.view(args.batch_size,-1), targetSeq.view(args.batch_size,-1))
RuntimeError: view size is not compatible with input tensor's size and stride (at least one dimension spans across two contiguous subspaces). Use .reshape(...) instead.

Could you please review it. Thank you

chickenbestlover commented 4 years ago

The script works in my environment: python 3.6 pytorch 1.4

(jmpark_py36) rit@rit:/media/rit/HDD/Engineering/RNN-Time-series-Anomaly-Detection$ python 1_train_predictor.py --data nyc_taxi --filename nyc_taxi.pkl

=> Start training from scratch
-----------------------------------------------------------------------------------------
Namespace(augment=True, batch_size=64, bptt=50, clip=10, data='nyc_taxi', device='cuda', dropout=0.2, emsize=32, epochs=400, eval_batch_size=64, filename='nyc_taxi.pkl', log_interval=10, lr=0.0002, model='LSTM', nhid=32, nlayers=2, prediction_window_size=10, pretrained=False, res_connection=False, resume=False, save_fig=False, save_interval=10, seed=1111, teacher_forcing_ratio=0.7, tied=False, weight_decay=0.0001)
-----------------------------------------------------------------------------------------
| epoch   1 |    10/   31 batches | ms/batch 52.9033 | loss  2.21 
| epoch   1 |    20/   31 batches | ms/batch 46.2340 | loss  2.01 
| epoch   1 |    30/   31 batches | ms/batch 46.1436 | loss  2.00 
-----------------------------------------------------------------------------------------
| end of epoch   1 | time:  1.84s | valid loss 1.9104 | 

Please specify your environment.

lhduc94 commented 4 years ago

It worked, thank you.