Accuracy in Semantic Segmentation

Hi All,

I am performing Semantic segmentation I can print the loss during the iteration using the code below

for iter in range(num_epochs):
    print(iter)	
    for (i,l) in trainloader:
        i= i.to(device)
        l = l.to(device=device, dtype=torch.int64)
        outt = model(i)
        loss = criterion(outt['out'], l.squeeze(1))
        print(loss)
        loss.backward()
        optimizer.step()

Is there a way to print out accuracy as well? Any help is appreciated

Thanks
Nishanth

Something like this should work:

N = 5
nb_classes = 10
h, w = 24, 24
output = torch.randn(N, nb_classes, h, w)
target = torch.randint(0, nb_classes, (N, h, w))

pred = torch.argmax(output, 1)
acc = (pred == target).float().mean()
1 Like