Predict labels and return percentage

I trained a model on 0 and 1 labels now I’m testing it on unlabeled data

for i, images in enumerate(imgset_loader):
    images =
    net = net.double()
    outputs = net(images)
    _, predicted = torch.max(, 1)

The last line returns an error : TypeError: only integer tensors of a single element can be converted to an index

I want the prediction to show a percentage of how many 0 labels it found on the data, how many 1s, and how many others.

Transform labels to a tensor via labels = torch.tensor(labels) and it should work.

def validation(model,device,data_loader_val):
correct = 0
total = 0
accuracy = 0.0
val_loss = 0.0
with torch.no_grad():
for data in data_loader_val:
images, true_labels = data
images,true_labels =, true_labels(device)
output = model(images)
val_loss += neural_funcs.cross_entropy(output,true_labels).item()
pred = output.max(1,keepdim=True)[1] #值,索引
correct += pred.eq(true_labels.view_as(pred)).sum().item()
val_loss /= len(data_loader_val.dataset)
total = len(data_loader_val.dataset)
accuracy = correct/total



true_labels seems to be a tensor, so your code seems to be missing the .to() operation.