code: def evaluate(model, val_loader, batch_transforms, val_metric):
      # Reset val metric
      val_metric.reset()
      # Validation loop
      val_loss, batch_cnt = 0, 0
      for images, targets in tqdm(val_loader):
          images = batch_transforms(images)
          targets = [{CLASS_NAME: t["boxes"]} for t in targets]
          out = model(
              images, targets, training=False, 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"].numpy()
          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_tensorflow.py
imports: import os
  from doctr.file_utils import CLASS_NAME
  import multiprocessing
  import time
  from pathlib import Path
  import psutil
  import tensorflow
  from tensorflow.keras import mixed_precision
  from tqdm import tqdm
  from doctr import datasets
  from doctr import transforms
  from doctr.datasets import DataLoader
  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) and returns: val_loss,  recall,  precision,  mean_iou