Herlev Pap smear Image classification

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.

The classes are as follows -

What I need to do is create a metric that can classify the cells into two categories

Normal and abnormal from the above 7 classes

Do I have to train two different models or is there a workaround that I can do??

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??

Or do I have to modify the dataset as a multi-label classification problem ??

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()