code: def _generate_epoch(
      self, text_only
  ) -> Generator[InputSample, None, None]:
      filenames = list(self.params.files)
      if self.mode == PipelineMode.TRAINING:
          shuffle(filenames)
  
      for filename in filenames:
          basename = split_all_ext(filename)[0]
          with h5py.File(filename, "r") as f:
              codec = list(map(chr, f["codec"]))
              if text_only:
                  for i, (text, idx) in enumerate(
                      zip(
                          f["transcripts"], range(len(f["transcripts"]))
                      )
                  ):
                      text = "".join([codec[c] for c in text])
                      fold_id = (
                          idx % self.params.n_folds
                          if self.params.n_folds > 0
                          else -1
                      )
                      yield InputSample(
                          None,
                          text,
                          SampleMeta(
                              id=f"{basename}/{i}", fold_id=fold_id
                          ),
                      )
              else:
                  gen = zip(
                      f["images"],
                      f["images_dims"],
                      f["transcripts"],
                      range(len(f["images"])),
                  )
                  if self.mode == PipelineMode.TRAINING:
                      gen = list(gen)
                      shuffle(gen)
  
                  for i, (image, shape, text, idx) in enumerate(gen):
                      image = np.reshape(image, shape)
                      text = "".join([codec[c] for c in text])
                      fold_id = (
                          idx % self.params.n_folds
                          if self.params.n_folds > 0
                          else -1
                      )
                      yield InputSample(
                          image,
                          text,
                          SampleMeta(
                              id=f"{basename}/{i}", fold_id=fold_id
                          ),
                      )
  
imports: from copy import deepcopy
  from dataclasses import dataclass, field
  from random import shuffle
  from typing import Generator, List
  from paiargparse import pai_dataclass, pai_meta
  from tfaip.data.pipeline.definitions import PipelineMode
  import numpy
  import h5py
  from calamari_ocr.ocr.dataset.datareader.base import CalamariDataGenerator, InputSample, SampleMeta, CalamariDataGeneratorParams
  from calamari_ocr.utils import split_all_ext, glob_all
label_desc: Use image node_id 5 for calling the Hdf5Generator obj's underlying member method code with example usage: obj._generate_epoch(text_only) without return types