code: def _load_sample(
      self, sample, text_only
  ) -> Generator[InputSample, None, None]:
      loader = PageXMLDatasetLoader(
          self.mode,
          self.params.non_existing_as_empty,
          self.params.text_index,
          self.params.skip_invalid,
          self.params.skip_commented,
      )
      image_path, xml_path, idx = sample
  
      img = None
      if self.mode in INPUT_PROCESSOR:
          img = self._load_image(image_path)
  
      for i, sample in enumerate(loader.load(image_path, xml_path)):
          fold_id = (
              (idx + i) % self.params.n_folds
              if self.params.n_folds > 0
              else -1
          )
          text = sample["text"]
          orientation = sample["orientation"]
  
          if not text_only and self.mode in INPUT_PROCESSOR:
              ly, lx = img.shape[:2]
  
              # rotate by orientation angle in clockwise direction to correct present skew
              angle = (
                  orientation
                  if orientation and orientation % 360 != 0
                  else 0
              )
  
              line_img = PageXMLReader.cutout(
                  img,
                  sample["coords"],
                  mode=self.params.cut_mode,
                  angle=angle,
                  cval=None,
                  scale=lx / sample["img_width"],
              )
  
              # add padding as required from normal files
              if self.params.pad:
                  img = np.pad(
                      img,
                      self.params.pad,
                      mode="constant",
                      constant_values=img.max(initial=0),
                  )
          else:
              line_img = None
  
          yield InputSample(
              line_img,
              text,
              SampleMeta(id=sample["id"], fold_id=fold_id),
          )
  
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 18 for calling the PageXMLReader obj's underlying member method code with example usage: obj._load_sample(sample, text_only) without return types