to_categorical should go before get_num_classes in metrics/functional/classification.py
pytorch-lightning/pytorch_lightning/metrics/functional/classification.py
    
    
        Lines 174 to 178
      in
      d18b9ef
    
  
  
    

        
          
           num_classes = get_num_classes(pred=pred, target=target, 
        

        
          
                                         num_classes=num_classes) 
        

        
          
            
        

        
          
           if pred.ndim == target.ndim + 1: 
        

        
          
               pred = to_categorical(pred, argmax_dim=argmax_dim) 
        
    
  


to_categorical should go before get_num_classes, since get_num_classes assumes pred has already been turned into categories (it is doing int(pred.max().detach().item() + 1)).
Warnings are raised now and then with current code, for example:
UserWarning: You have set 10 number of classes if different from predicted (xx) and target (10) number of classes

If logits are passed in directly for metrics.