RuntimeError: already counted a million dimensions in a given sequence. Most likely your items are also sequences and there's no way to infer how many dimension should the tensor have using variables

I read all posts regarding the same problem but couldn’t figure my error out.

def main(A, B, num_epochs):
    n = A.shape[0]
    dim = A.shape[1]
    C = range(0, n - 1)
    train_loader = zip(A, B, C)

    # Training the Model
    for epoch in range(num_epochs):
        shuffle(train_loader)
        for (x, y,  i) in train_loader:
            x = Variable(torch.FloatTensor(x), requires_grad=False)
            y = Variable(torch.FloatTensor(y), requires_grad=False)

RuntimeError: already counted a million dimensions in a given sequence. Most likely your items are also sequences and there’s no way to infer how many dimension should the tensor have

The error occurs when calling

            x = Variable(torch.FloatTensor(x), requires_grad=False)

I also tried:

            x = Variable(torch.FloatTensor(x).data, requires_grad=False)

which resulted in the same error.

The reason I added x conversion to torch because otherwise I get this error:

            x = Variable(x, requires_grad=False)

RuntimeError: Variable data has to be a tensor, but got matrix

x.shape and y.shape are (1,300)

Of what type is x? Is it a numpy array?
If so, what dtype does it have?

A small side note: based on your code it looks like your pytorch version is < 0.4.0. You should consider updating to the latest stable release. Have a look at the website for install instructions.

1 Like

x is of type: numpy.matrixlib.defmatrix.matrix
when converting to numpy array it works.

thanks.

Ok, thanks for the info.
Could you try to wrap x and y into np.asarray(x)?

1 Like