RuntimeError: expand(torch.cuda.FloatTensor{[1, 3, 256, 256]}, size=[3, 256, 256]): the number of sizes provided (3) must be greater or equal to the number of dimensions in the tensor (4)

I get this with Python3.6, Pytorch 1.0.1.post2 on a linux.

Here’s the line of code raising this:

val_batch_output[idx,:,:,:].copy_(x_hat_val.data)

RuntimeError: expand(torch.cuda.FloatTensor{[1, 3, 256, 256]}, size=[3, 256, 256]): the number of sizes provided (3) must be greater or equal to the number of dimensions in the tensor (4)

I think your x_hat_val data is of shape (1, 3, 256, 256) whereas val_batch_output requires data of shape (3, 256, 256). Try removing the first 1 dim from the data.

val_batch_output[idx,:,:,:].copy_(x_hat_val.data.squeeze())
1 Like