RNN - RuntimeError: Input Must Have 3 Dimensions, Got 2
I’m getting the following error: RuntimeError: input must have 3 dimensions, got 2 I have a single feature column that I am trying to feed into a GRU neural net. Below are my d
Solution 1:
As suggested by the error you got, the input tensor shape expected by the GRU is three dimensional with shape (batch_size, seq_len, input_size)1
But you are feeding a tensor of shape (10, 5). You said your input has one feature value, so you should add a dimension for input_size of size 1. This can be done like this
sample_x.unsqueeze(-1)
Solution 2:
Actually error itself tells you the problem. The RNN class which is super class of the GRU, expects an input shape with:
(#batch,#number_of_timesteps,#number_of_features)
So for your case you have 1 feature, 5 timesteps. At your dataloader you need to expand the X to (#batch,5,1).
Post a Comment for "RNN - RuntimeError: Input Must Have 3 Dimensions, Got 2"