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):
          try:
              if torch.cuda.is_available():
                  images = images.cuda()
              images = batch_transforms(images)
              if amp:
                  with torch.cuda.amp.autocast():
                      out = model(images, targets, return_preds=True)
              else:
                  out = model(images, targets, return_preds=True)
              # Compute metric
              if len(out["preds"]):
                  words, _ = zip(*out["preds"])
              else:
                  words = []
              val_metric.update(targets, words)
  
              val_loss += out["loss"].item()
              batch_cnt += 1
          except ValueError:
              print(
                  f"unexpected symbol/s in targets:\n{targets} \n--> skip batch"
              )
              continue
  
      val_loss /= batch_cnt
      result = val_metric.summary()
      return val_loss, result["raw"], result["unicase"]
  
file_path: doctr/references/recognition/evaluate_pytorch.py
imports: import os
  import multiprocessing
  import time
  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.datasets import VOCABS
  from doctr.models import recognition
  from doctr.utils.metrics import TextMatch
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,  result,  result