code: def top_k_accuracy(
      output: Tensor, target: Tensor, top_k: Optional[tuple] = (1,)
  ) -> list:
      maximum_k = max(top_k)
      batch_size = target.shape[0]
  
      _, pred = output.topk(maximum_k, 1, True, True)
      pred = pred.t()
      correct = pred.eq(target.reshape(1, -1).expand_as(pred))
  
      results = []
      for k in top_k:
          correct_k = (
              correct[:k].reshape(-1).float().sum(0, keepdim=True)
          )
          acc_k = correct_k.mul_(100.0 / batch_size)
          results.append(acc_k)
      return results
  
file_path: ml-cvnets/metrics/topk_accuracy.py
imports: from typing import Any, Dict, Optional, Union
  from torch import Tensor
  from metrics import METRICS_REGISTRY
  from metrics.metric_base import AverageMetric
  from utils import logger
label_desc: Use image node_id 1 for calling a global function with example usage: top_k_accuracy(output, target, top_k) and returns: results