Hi all
I just want to calculate the semantic segmentation metric values like : pixel accuracy, mIoU
and Kappa metric
and I found some code and then I adjust it as follows:
my question is:
are these functions ok to calculate the above metric? if not can you suggest me any thing else
from sklearn.metrics import jaccard_score,cohen_kappa_score
def pixel_accuracy(Pred, ground_truth):
 with torch.no_grad():*

Pred = torch.argmax(Pred, dim=1) #dim =1 => over rows *

correct = torch.eq(Pred, ground_truth).int() # the o/p here is 0 , 1 *

accuracy = float(correct.sum()) / float(correct.numel())*
 return accuracy*
def mIoU(pred, ground_truth, smooth=1e10, n_classes=5):

with torch.no_grad():*

# normalize the output becuse (we have identity activation functions) linear (same output)*

pred = torch.argmax(Pred, dim=1)*

pred = pred.cpu().contiguous().view(1).numpy() # make it 1D *

ground_truth = ground_truth.cpu().contiguous().view(1).numpy() # make it 1D *

MIoU=jaccard_score(ground_truth, pred,average='macro') #'none' per class *

return MIoU*
def kapp_score_Value(pred, ground_truth):
 with torch.no_grad():*

pred = torch.argmax(Pred, dim=1)*

pred = pred.cpu().contiguous().view(1).numpy() # make it 1D *

ground_truth = ground_truth.cpu().contiguous().view(1).numpy() # make it 1D *

*

kapp_score = cohen_kappa_score(ground_truth, pred_mask) *

*
 return kapp_score*
*in mean code: *
*I just call them like this : *
pred = model(image)
acc = pixel_accuracy(Pred, ground_truth)
MiouVal = mIoU(Pred, ground_truth)
kappavalue = kapp_score_Value(Pred, ground_truth)