code: def evaluate(
      model, device, 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):
          images = images.to(device)
          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
  
      val_loss /= batch_cnt
      result = val_metric.summary()
      return val_loss, result["raw"], result["unicase"]
  
imports: import os
  import datetime
  import hashlib
  import multiprocessing
  import time
  from pathlib import Path
  import numpy
  import torch
  import torch.distributed
  import torch.multiprocessing
  import wandb
  from torch.nn.parallel import DistributedDataParallel
  from torch.optim.lr_scheduler import CosineAnnealingLR, OneCycleLR
  from torch.utils.data import DataLoader, SequentialSampler
  from torch.utils.data.distributed import DistributedSampler
  from torchvision.transforms.v2 import Compose, GaussianBlur, Normalize, RandomGrayscale, RandomPerspective, RandomPhotometricDistort
  from tqdm.auto import tqdm
  from doctr import transforms
  from doctr.datasets import VOCABS, RecognitionDataset, WordGenerator
  from doctr.models import login_to_hub, push_to_hf_hub, recognition
  from doctr.utils.metrics import TextMatch
  from utils import EarlyStopper, plot_samples
label_desc: Use image node_id 2 for calling a global function with example usage: evaluate(model, device, val_loader, batch_transforms, val_metric, amp) and returns: val_loss,  result,  result