Can you show the result of those print statements?



 minhoha:

print(mlp_train_inputs)
print(mlp_train_targets)


You move the data to cuda but the labels remain in the CPU, it is not necessary to move the data to gpu here, since you do it later in the training loop. Furthermore, is this loop creating what you expect? It looks as if only the last batch would be stored.



 minhoha:

for batch_idx, (inputs, targets) in enumerate(train_loader2):
mlp_train_inputs = F.max_pool2d(inputs, kernel_size=8, stride=8).view(F.max_pool2d(inputs, kernel_size=8, stride=8).size(0),-1).cuda()


I think I found the issue in that same loop. F.max_pool2d requires a Variable as input in v0.3 so it shouldn’t execute at all, so I assume you’re using v0.2, which accepts a Tensor as input but silently returns a Variable. This would cause mlp_train_inputs to be a Variable, which would cause the error in your dataloader, but since mlp_train_targets is not a Variable it raised a runtime error when you tried it with .data
So if this is indeed the problem replace



 minhoha:

mlp_train_dataset = torch.utils.data.TensorDataset(mlp_train_inputs, mlp_train_targets)


with

mlp_train_dataset = torch.utils.data.TensorDataset(mlp_train_inputs.data, mlp_train_targets)

Hopefully this will solve the problem