code: def evaluate(model, criterion, data_loader, device):
      model.eval()
      metric_logger = utils.MetricLogger(delimiter="  ")
      header = "Test:"
      num_processed_samples = 0
      # Group and aggregate output of a video
      num_videos = len(data_loader.dataset.samples)
      num_classes = len(data_loader.dataset.classes)
      agg_preds = torch.zeros(
          (num_videos, num_classes), dtype=torch.float32, device=device
      )
      agg_targets = torch.zeros(
          (num_videos), dtype=torch.int32, device=device
      )
      with torch.inference_mode():
          for video, target, video_idx in metric_logger.log_every(
              data_loader, 100, header
          ):
              video = video.to(device, non_blocking=True)
              target = target.to(device, non_blocking=True)
              output = model(video)
              loss = criterion(output, target)
  
              # Use softmax to convert output into prediction probability
              preds = torch.softmax(output, dim=1)
              for b in range(video.size(0)):
                  idx = video_idx[b].item()
                  agg_preds[idx] += preds[b].detach()
                  agg_targets[idx] = target[b].detach().item()
  
              acc1, acc5 = utils.accuracy(output, target, topk=(1, 5))
              # FIXME need to take into account that the datasets
              # could have been padded in distributed setup
              batch_size = video.shape[0]
              metric_logger.update(loss=loss.item())
              metric_logger.meters["acc1"].update(
                  acc1.item(), n=batch_size
              )
              metric_logger.meters["acc5"].update(
                  acc5.item(), n=batch_size
              )
              num_processed_samples += batch_size
      # gather the stats from all processes
      num_processed_samples = utils.reduce_across_processes(
          num_processed_samples
      )
      if isinstance(data_loader.sampler, DistributedSampler):
          # Get the len of UniformClipSampler inside DistributedSampler
          num_data_from_sampler = len(data_loader.sampler.dataset)
      else:
          num_data_from_sampler = len(data_loader.sampler)
  
      if (
          hasattr(data_loader.dataset, "__len__")
          and num_data_from_sampler != num_processed_samples
          and torch.distributed.get_rank() == 0
      ):
          # See FIXME above
          warnings.warn(
              f"It looks like the sampler has {num_data_from_sampler} samples, but {num_processed_samples} "
              "samples were used for the validation, which might bias the results. "
              "Try adjusting the batch size and / or the world size. "
              "Setting the world size to 1 is always a safe bet."
          )
  
      metric_logger.synchronize_between_processes()
  
      print(
          " * Clip Acc@1 {top1.global_avg:.3f} Clip Acc@5 {top5.global_avg:.3f}".format(
              top1=metric_logger.acc1, top5=metric_logger.acc5
          )
      )
      # Reduce the agg_preds and agg_targets from all gpu and show result
      agg_preds = utils.reduce_across_processes(agg_preds)
      agg_targets = utils.reduce_across_processes(
          agg_targets, op=torch.distributed.ReduceOp.MAX
      )
      agg_acc1, agg_acc5 = utils.accuracy(
          agg_preds, agg_targets, topk=(1, 5)
      )
      print(
          " * Video Acc@1 {acc1:.3f} Video Acc@5 {acc5:.3f}".format(
              acc1=agg_acc1, acc5=agg_acc5
          )
      )
      return metric_logger.acc1.global_avg
  
file_path: vision/references/video_classification/train.py
imports: import datetime
  import os
  import time
  import warnings
  import datasets
  import presets
  import torch
  import torch.utils.data
  import torchvision
  import torchvision.datasets.video_utils
  import utils
  from torch import nn
  from torch.utils.data.dataloader import default_collate
  from torchvision.datasets.samplers import DistributedSampler, RandomClipSampler, UniformClipSampler
label_desc: Use image node_id 2 for calling a global function with example usage: evaluate(model, criterion, data_loader, device) and returns: metric_logger