code: def recognizer_predict(
      model,
      converter,
      test_loader,
      batch_max_length,
      ignore_idx,
      char_group_idx,
      decoder="greedy",
      beamWidth=5,
      device="cpu",
  ):
      model.eval()
      result = []
      with torch.no_grad():
          for image_tensors in test_loader:
              batch_size = image_tensors.size(0)
              image = image_tensors.to(device)
              # For max length prediction
              length_for_pred = torch.IntTensor(
                  [batch_max_length] * batch_size
              ).to(device)
              text_for_pred = (
                  torch.LongTensor(batch_size, batch_max_length + 1)
                  .fill_(0)
                  .to(device)
              )
  
              preds = model(image, text_for_pred)
  
              # Select max probabilty (greedy decoding) then decode index to character
              preds_size = torch.IntTensor([preds.size(1)] * batch_size)
  
              ######## filter ignore_char, rebalance
              preds_prob = F.softmax(preds, dim=2)
              preds_prob = preds_prob.cpu().detach().numpy()
              preds_prob[:, :, ignore_idx] = 0.0
              pred_norm = preds_prob.sum(axis=2)
              preds_prob = preds_prob / np.expand_dims(
                  pred_norm, axis=-1
              )
              preds_prob = (
                  torch.from_numpy(preds_prob).float().to(device)
              )
  
              if decoder == "greedy":
                  # Select max probabilty (greedy decoding) then decode index to character
                  _, preds_index = preds_prob.max(2)
                  preds_index = preds_index.view(-1)
                  preds_str = converter.decode_greedy(
                      preds_index.data.cpu().detach().numpy(),
                      preds_size.data,
                  )
              elif decoder == "beamsearch":
                  k = preds_prob.cpu().detach().numpy()
                  preds_str = converter.decode_beamsearch(
                      k, beamWidth=beamWidth
                  )
              elif decoder == "wordbeamsearch":
                  k = preds_prob.cpu().detach().numpy()
                  preds_str = converter.decode_wordbeamsearch(
                      k, beamWidth=beamWidth
                  )
  
              preds_prob = preds_prob.cpu().detach().numpy()
              values = preds_prob.max(axis=2)
              indices = preds_prob.argmax(axis=2)
              preds_max_prob = []
              for v, i in zip(values, indices):
                  max_probs = v[i != 0]
                  if len(max_probs) > 0:
                      preds_max_prob.append(max_probs)
                  else:
                      preds_max_prob.append(np.array([0]))
  
              for pred, pred_max_prob in zip(preds_str, preds_max_prob):
                  confidence_score = custom_mean(pred_max_prob)
                  result.append([pred, confidence_score])
  
      return result
  
imports: from PIL import Image
  import torch
  import torch.backends.cudnn
  import torch.utils.data
  import torch.nn.functional
  import torchvision.transforms
  import numpy
  from collections import OrderedDict
  import importlib
  from .utils import CTCLabelConverter
  import math
label_desc: Use image node_id 4 for calling a global function with example usage: recognizer_predict(model, converter, test_loader, batch_max_length, ignore_idx, char_group_idx, decoder, beamWidth, device) and returns: result