tejaslodaya / timeseries-clustering-vae

Variational Recurrent Autoencoder for timeseries clustering in pytorch
GNU General Public License v3.0
462 stars 82 forks source link

regarding the _train method number of dimension error #18

Closed tarmaac closed 1 year ago

tarmaac commented 1 year ago

Hi! Im a bit confused. In the first steps of the train method in vrae.py

Index first element of array to return tensor

X = X[0]

this implies selecting the first element of the batch from train loader in that case X we will have only 2 dimensions. since it will only be a single timeseries. (seq_len x num_of_features)

but the following instruction is:

required to swap axes, since dataloader gives output in (batch_size x seq_len x num_of_features)

X = X.permute(1,0,2)

Where X needs to be a 3 dimensional array thus I got an error (number of dimensions in the tensor input does not match the length of the desired ordering of dimensions i.e. input.dim() = 2 is not equal to len(dims) = 3)

Is this an error ? or am I forgetting something? thanks in advance for your response.

CharlotteE67 commented 1 year ago

I think that you should consider batch size, which means that X's size needs to be [batch_size, seq_len, num_of_features]. If you still use single training data, maybe take batch_size as 1 and unsqueeze it into size of [1, seq_len, num_of_features] so that the codes will work.

tarmaac commented 1 year ago

Thanks! I found that I wasnt casting the numpy dataset into a torch tensor before calling the TensorDataset class, now it works.