code: def evaluate(model, val_loader, batch_transforms, val_metric):
      # Reset val metric
      val_metric.reset()
      # Validation loop
      val_loss, batch_cnt = 0, 0
      val_iter = iter(val_loader)
      for images, targets in tqdm(val_iter):
          images = batch_transforms(images)
          out = model(
              images, targets, return_preds=True, training=False
          )
          # Compute metric
          if len(out["preds"]):
              words, _ = zip(*out["preds"])
          else:
              words = []
          val_metric.update(targets, words)
  
          val_loss += out["loss"].numpy().mean()
          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 tensorflow
  from tensorflow.keras import mixed_precision
  from tqdm.auto import tqdm
  from doctr.models import login_to_hub, push_to_hf_hub
  from doctr import transforms
  from doctr.datasets import VOCABS, DataLoader, RecognitionDataset, WordGenerator
  from doctr.models import recognition
  from doctr.utils.metrics import TextMatch
  from utils import EarlyStopper, plot_recorder, plot_samples
label_desc: Use image node_id 3 for calling a global function with example usage: evaluate(model, val_loader, batch_transforms, val_metric) and returns: val_loss,  result,  result