I am trying to calculate f-1 accuracy for to solve multi-class segmentation problem.I am using cross-entropy loss.
Below is my code -
def dice_test(loaders,model,criterion,use_cuda):
running_loss = 0
total_train = 0
accuracy = 0
for batch_idx ,(data,target) in enumerate(loaders):
if use_cuda:
data,target = data.cuda(),target.cuda()
output = model(data)
loss = criterion(output,target)
test_loss += test_loss + ((1 / (batch_idx + 1)) * (loss.data - test_loss))
_, predicted = torch.max(output.data, 1)
accuracy += f1_score(target,predicted>0.5,average = 'micro')
total_train += target.nelement()
print(accuracy/total_train)
But I am getting ValueError: unknown is not supported
.
My dataset is highly unbalanced. Any other right way to measure accuracy is also welcomed.