Not sure, what’s causing the higher number of samples in your confusion matrix, but the code seems to be fine generally:
m = torch.zeros(10, 10)

pred = torch.randint(0, 10, (100,))
target = torch.randint(0, 10, (100,))

for t, p in zip(target.view(-1), pred.view(-1)):
    m[t.long(), p.long()] += 1

print(m.sum())
> tensor(100.)




 ssalome:

weight and SD for grey scale images for using pretrained resnet 18?


Do you mean the mean and standard deviation for normalization?
If so, you could either calculate if from your training dataset or alternatively start with 0.5 for both values.