data, target = data.cuda(), target.cuda()
data, target = Variable(data, volatile=True), Variable(target)
s_output, t_output = model(data, data)
test_loss += F.nll_loss(F.log_softmax(s_output, dim = 1), target, size_average=False).data[0] // sum up batch loss
pred = s_output.data.max(1)[1] // get the index of the max log-probability
correct += pred.eq(target.data.view_as(pred)).cpu().sum()
After Change
for tgt_test_data, tgt_test_label in tgt_test_loader:
if cuda:
tgt_test_data, tgt_test_label = tgt_test_data.cuda(), tgt_test_label.cuda()
tgt_test_data, tgt_test_label = Variable(tgt_test_data), Variable(tgt_test_label)
tgt_pred, mmd_loss = model(tgt_test_data, tgt_test_data)
test_loss += F.nll_loss(F.log_softmax(tgt_pred, dim = 1), tgt_test_label, reduction="sum").item() // sum up batch loss
pred = tgt_pred.data.max(1)[1] // get the index of the max log-probability
correct += pred.eq(tgt_test_label.data.view_as(pred)).cpu().sum()