This line of code might yield this error:
data = Variable(data).unsqueeze(0)



Variables are deprecated since PyTorch 0.4 so use tensors directly now.
Most likely you don’t need to unsqueeze the data tensor, as the DataLoader would return the batch in the shape [batch_size, channels, height, width]. However, it seems you are somehow avoiding the DataLoader and try to get some images directly via test_loader.dataset.imgs?