code: def evaluate(
      model, val_loader, batch_transforms, val_metric, amp=False
  ):
      # Model in eval mode
      model.eval()
      # Reset val metric
      val_metric.reset()
      # Validation loop
      val_loss, batch_cnt = 0, 0
      for images, targets in tqdm(val_loader):
          if torch.cuda.is_available():
              images = images.cuda()
          images = batch_transforms(images)
          targets = [{CLASS_NAME: t["boxes"]} for t in targets]
          if amp:
              with torch.cuda.amp.autocast():
                  out = model(images, targets, return_preds=True)
          else:
              out = model(images, targets, return_preds=True)
          # Compute metric
          loc_preds = out["preds"]
          for target, loc_pred in zip(targets, loc_preds):
              for boxes_gt, boxes_pred in zip(
                  target.values(), loc_pred.values()
              ):
                  # Remove scores
                  val_metric.update(
                      gts=boxes_gt, preds=boxes_pred[:, :-1]
                  )
  
          val_loss += out["loss"].item()
          batch_cnt += 1
  
      val_loss /= batch_cnt
      recall, precision, mean_iou = val_metric.summary()
      return val_loss, recall, precision, mean_iou
  
file_path: doctr/references/detection/evaluate_pytorch.py
imports: import os
  from doctr.file_utils import CLASS_NAME
  import logging
  import multiprocessing
  import time
  from pathlib import Path
  import psutil
  import torch
  from torch.utils.data import DataLoader, SequentialSampler
  from torchvision.transforms import Normalize
  from tqdm import tqdm
  from doctr import datasets
  from doctr import transforms
  from doctr.models import detection
  from doctr.utils.metrics import LocalizationConfusion
label_desc: Use image node_id 1 for calling a global function with example usage: evaluate(model, val_loader, batch_transforms, val_metric, amp) and returns: val_loss,  recall,  precision,  mean_iou