chickenbestlover / RNN-Time-series-Anomaly-Detection

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

Runtime error running example #45

Open kb1ooo opened 4 years ago

kb1ooo commented 4 years ago

Just trying one of the ECG examples and getting a runtime error. I'm running pytorch 1.5.

$ python 1_train_predictor.py --data ecg --filename chfdb_chf01_275.pkl --emsize 128 --nhid 128 --save_fig --epoch 600
=> Start training from scratch
-----------------------------------------------------------------------------------------
Namespace(augment=True, batch_size=64, bptt=50, clip=10, data='ecg', device='cuda', dropout=0.2, emsize=128, epochs=600, eval_batch_size=64, filename='chfdb_chf01_275.pkl', log_interval=10, lr=0.0002, model='LSTM', nhid=128, nlayers=2, prediction_window_size=10, pretrained=False, res_connection=False, resume=False, save_fig=True, save_interval=10, seed=1111, teacher_forcing_ratio=0.7, tied=False, weight_decay=0.0001)
-----------------------------------------------------------------------------------------
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
/home/marc/dev/RNN-Time-series-Anomaly-Detection/1_train_predictor.py in <module>
    318 
    319             epoch_start_time = time.time()
--> 320             train(args,model,train_dataset,epoch)
    321             val_loss = evaluate(args,model,test_dataset)
    322             print('-' * 89)

/home/marc/dev/RNN-Time-series-Anomaly-Detection/1_train_predictor.py in train(args, model, train_dataset, epoch)
    226             outSeq1 = torch.cat(outVals,dim=0)
    227             hids1 = torch.cat(hids1,dim=0)
--> 228             loss1 = criterion(outSeq1.view(args.batch_size,-1), targetSeq.view(args.batch_size,-1))
    229 
    230             '''Loss2: Teacher forcing loss'''

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.
lzt-pro commented 4 years ago

I have the same problem. Do you find the way to love it?

kb1ooo commented 4 years ago

@lzt-pro yes. Lines 228, 232, 279, 283 change occurrences of .view to .contiguous().view

gireeshkbogu commented 4 years ago

I get this error when I change the view to contiguous

(base)a@x86_64-apple-darwin13 RNN-Time-series-Anomaly-Detection-master %  python 1_train_predictor.py --data nyc_taxi --filename nyc_taxi.pkl --device cpu
=> Start training from scratch
-----------------------------------------------------------------------------------------
Namespace(augment=True, batch_size=64, bptt=50, clip=10, data='nyc_taxi', device='cpu', 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)
-----------------------------------------------------------------------------------------
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 235, in train
    loss3 = criterion(hids1(args.batch_size,-1), hids2(args.batch_size,-1).detach())
TypeError: 'Tensor' object is not callable