slavakung:

data


First up, I understand that you’re training and autoencoder, so you want to get the loss between the data and output. In that case, you need to either somehow use target to be the same as the data, or use a different loss function. NLL_loss is used for classification into n classes. What you need is probably a different loss function.
But, if you just want to run the code you gave me here, I think I found the error. It’s probably in the line
 loss = F.cross_entropy(output, data)

Loss takes in output and TARGET, not data. when you read using data loader into (data,target) your data stores input data and target stores their ground truth labels. The loss is calculated on predicted labels (output) and the ground truth label (target).
So, that might be the error. So, including the change I mentioned in the previous answer, all the changes are -
target.Long()
target = Variable(target)
loss = F.cross_entropy(output, target)

so you either somehow mask your target to be your data (but I doubt that’s possible), or else you use a different loss function.