PCA on torch.Datasets.SVHN

I am working on a machine-learning classification model. It works fine on greyscale data set. But the performance on RGB images is poor. So, I decided to apply torch.pca_lowrank on the RGB data set to see if this can improve the feature representations and the model’s performance.

Here is my code sample:

U, S, V = torch.pca_lowrank(torch.as_tensor(train_dataset) , q=None, center=True, niter=3)
train_dataset = torch.matmul(train_dataset, V[:, :n_components])

I am getting this error:

ValueError: only one element tensors can be converted to Python scalars

Any suggestions, please? Thanks.

torch.as_tensor(train_dataset) looks wrong as it seems you are trying to transform the entire dataset into a single tensor. If you’ve preloaded all samples in your Dataset, access this data directly and pass it to pca_lowrank instead.

Thank you @ptrblck!
That saves my day.