code: def _samples_gt_from_book(
      self, root, img, page_id
  ) -> Iterable[Dict[str, Any]]:
      ns = {"ns": root.nsmap[root.prefix]}
      page = root.find(".//ns:Page", namespaces=ns)
      imgfile = page.attrib.get("imageFilename")
      if (
          self.mode in {PipelineMode.TRAINING, PipelineMode.EVALUATION}
      ) and not split_all_ext(img)[0].endswith(
          split_all_ext(imgfile)[0]
      ):
          logger.warning(
              "Mapping of image file to xml file invalid: {} vs {} (comparing basename {} vs {})".format(
                  img,
                  imgfile,
                  split_all_ext(img)[0],
                  split_all_ext(imgfile)[0],
              )
          )
  
      img_w = int(page.attrib.get("imageWidth"))
      textlines = root.findall(".//ns:TextLine", namespaces=ns)
  
      for textline in textlines:
          tequivs = textline.findall(
              './ns:TextEquiv[@index="{}"]'.format(self.text_index),
              namespaces=ns,
          )
  
          if not tequivs:
              tequivs = [
                  te
                  for te in textline.findall(
                      "./ns:TextEquiv", namespaces=ns
                  )
                  if "index" not in te.attrib
              ]
  
          if len(tequivs) > 1:
              logger.warning(
                  "PageXML is invalid: TextLine includes TextEquivs with non unique ids"
              )
  
          if self.skip_commented and len(
              textline.attrib.get("comments", "")
          ):
              continue
  
          if tequivs is not None and len(tequivs) > 0:
              l = tequivs[0]
              uc = l.find("./ns:Unicode", namespaces=ns)
              text = uc.text if uc is not None else ""
              if text is None:
                  # Handle empty tag as empty string not as "not existing"
                  text = ""
          else:
              l = None
              text = None
  
          if text is None:
              if self.skip_invalid:
                  continue
              elif self._non_existing_as_empty:
                  text = ""
              else:
                  raise Exception("Empty text field")
  
          orientation = float(
              textline.getparent().attrib.get("orientation", default=0)
          )
  
          if self.mode in {
              PipelineMode.TRAINING,
              PipelineMode.EVALUATION,
          }:
              if len(text) == 0:
                  # Empty lines cannot be used for training (CTC-loss can not be computed)
                  continue
  
          yield {
              "page_id": page_id,
              "ns": ns,
              "rtype": textline.getparent().attrib.get(
                  "type", default=""
              ),
              "xml_element": textline,
              "image_path": img,
              "id": "{}/{}".format(page_id, textline.attrib.get("id")),
              "base_name": textline.attrib.get("id"),
              "text": text,
              "coords": textline.find(
                  "./ns:Coords", namespaces=ns
              ).attrib.get("points"),
              "orientation": orientation,
              "img_width": img_w,
          }
  
imports: import os
  from copy import deepcopy
  from dataclasses import dataclass, field
  from random import shuffle
  import math
  import numpy
  from paiargparse import pai_dataclass, pai_meta
  from tfaip.data.pipeline.definitions import PipelineMode, INPUT_PROCESSOR, TARGETS_PROCESSOR
  from tqdm import tqdm
  from lxml import etree
  import cv2
  from typing import List, Generator, Optional, Iterable, Dict, Any, Tuple
  from enum import IntEnum
  from calamari_ocr.ocr.dataset.datareader.base import CalamariDataGenerator, CalamariDataGeneratorParams, InputSample, SampleMeta
  from calamari_ocr.utils import split_all_ext, filename, glob_all
  from calamari_ocr.ocr.predict.params import Prediction
  import logging
label_desc: Use image node_id 3 for calling the PageXMLDatasetLoader obj's underlying member method code with example usage: obj._samples_gt_from_book(root, img, page_id) without return types