Hello. I am using fast to perform image classification on Pap smear Herlev dataset. This dataset is organised into Imagenet style dataset. Moreover, I require to print out two accuracy metrics: One for binary classification and other for multi class classification.
If you just want to be quick, train for seven classes and then calculate accuracy for aggregated classes too. However, I would also train for binary classification, because you may have better binary accuracy.
Sir, I am training on binary classification first. Then I’ll use this as a pre-trained model for the multi classification. Would that turn out to be better??
So you are already training twice.
No need for multi-labels. I would compare accuracy of the first model vs accuracy calculated after training the second one, by aggregating 3 classes as normal and the other 4 as abnormal, and keep the best.
I did it…
Multiclass classification and binary classification metrics both at same time. Now I’ll use callbacks to look for improvements in both these metrics.
def binary_acc(preds, targets):
n = targets.shape[0]
preds = preds.argmax(dim=-1).view(n, -1)
targets = targets.view(-1, 1)
for i, (pred, target) in enumerate(zip(preds, targets)):
pred = 0 if pred.item() < 4 else 1
target = 0 if target.item() < 4 else 1
preds[i] = torch.tensor(pred, device="cuda:0")
targets[i] = torch.tensor(target, device="cuda:0")
return (preds==targets).float().mean()