Adding zeros to dataset

Hi, I want to add some zeros at the end of CIFAR-10 dataset. I tried this:

for batch_idx, (inputs, targets) in enumerate(trainloader):
            if use_cuda:
                inputs, targets = inputs.cuda(), targets.cuda()

                input_zero = torch.zeros(batch_size, 3, 5, 32).cuda()
                tragets_zero = torch.zeros(batch_size, 10).cuda()

             targets = torch.cat((targets, tragets_zero))
             inputs_new = torch.cat((inputs, input_zero), 2)

It shows this error at targets = torch.cat((targets, tragets_zero)):

RuntimeError: Expected object of scalar type Long but got scalar type Float for sequence element 1 in sequence argument at position #1 'tensors'

How can I solve this?

torch.zeros() gives tensors of type Float, but in this case it’s not what u want. So u should change it to Long type, like input_zero = torch.zeros(batch_size, 3, 5, 32).long().cuda() or input_zero = torch.zeros(batch_size, 3, 5, 32,dtype=torch.long,device=UR_GPU).

Thank you for your reply, @G.M. That solved the problem.

It seems there is another problem about targets = torch.cat((targets, tragets_zero)):

RuntimeError:  Tensors must have same number of dimensions: got 2 and 1 at /opt/conda/conda-bld/pytorch_.....

U should go and take a look at the doc for torch.cat. Then try to print out all the shapes of the 2 tensors. Finally, u’ll realize what’s wrong :slight_smile:

Ok. Thank you :slightly_smiling_face:

The issue here is quite straight forward.