Hi,
I’m using the following two functions to find the accuracy of my semantic segmentation network, I found this code on github and they seem to work but I dont exactly know how. I am trying to understand what each line is doing.
I have commented each line with what I think is going on, if I am wrong in my understanding can you please correct me.
The lines I need help in understanding are: values,indices = tensor.cpu().max(1) and incorrect=preds.ne(targets).cpu().sum()
def get_predictions(output_batch):
    bs, c, h, w = output_batch.size()           # size returns [batchsize, channels, rows, columns]
    tensor = output_batch.data
    values, indices = tensor.cpu().max(1)       # get the values and indices of the max values in every channel (dim=1),  why are we finding the maximum value in RGB channels? 
    indices = indices.view(bs, h, w)            # reshape it to this, as this is how 'targets' is shaped
    return indices


def error(preds, targets):
    assert preds.size() == targets.size()
    bs, h, w = preds.size()
    n_pixels = bs*h*w
    incorrect = preds.ne(targets).cpu().sum()       # I cannot find out what 'ne' is doing here and what are we summing?
    err = incorrect.numpy()/n_pixels                # converted this tensor to numpy as the tensor was int and division was giving 0 everytime
    # return err
    return round(err, 5)

Many Thanks