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: The expanded size of the tensor (32) must match the existing size (2) at non-singleton dimension 1 #13

Open chenshanghao opened 5 years ago

chenshanghao commented 5 years ago

The expanded size of the tensor (32) must match the existing size (2) at non-singleton dimension 1

When I tried to run your code via Notebook, this runtime error came.

--> 135 outVal, hidden_, hid = predictormodel.forward(outVal, hidden,return_hiddens=True) 136 outVals.append(outVal) 137 hids1.append(hid)

in forward(self, input, hidden, return_hiddens, noise) 71 print("*"*50) 72 # decoded = output.view(output.size(0)*output.size(1), output.size(2)) ---> 73 decoded = self.decoder(output.view(output.size(0)*output.size(1), output.size(2))) # [(seq_len x batch_size) * feature_size] 74 print(type(decoded)) 75 print(decoded.size()) ~/anaconda3/lib/python3.6/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs) 489 result = self._slow_forward(*input, **kwargs) 490 else: --> 491 result = self.forward(*input, **kwargs) 492 for hook in self._forward_hooks.values(): 493 hook_result = hook(self, input, result) ~/anaconda3/lib/python3.6/site-packages/torch/nn/modules/linear.py in forward(self, input) 53 54 def forward(self, input): ---> 55 return F.linear(input, self.weight, self.bias) 56 57 def extra_repr(self): ~/anaconda3/lib/python3.6/site-packages/torch/nn/functional.py in linear(input, weight, bias) 990 if input.dim() == 2 and bias is not None: 991 # fused op is marginally faster --> 992 return torch.addmm(bias, input, weight.t()) 993 994 output = input.matmul(weight.t()) RuntimeError: The expanded size of the tensor (32) must match the existing size (2) at non-singleton dimension 1
chickenbestlover commented 5 years ago

Did you just run 1_train_predictor.py without modifying it? Or did you modify some code?

chenshanghao commented 5 years ago

Hi chickenbestlover,

I was trying to migrate your code to notebook. I didn't modify anything and confirmed that the input to the function was same as your code.

Thanks, Chauncey

dan-r95 commented 4 years ago

Have you fixed that error? I was also experimenting with a jupyter notebook on google colab.

Dudududu15 commented 10 months ago

I also have this error