class_docstr: creates a test generator that iterates over entire given dataset returning 1 patient per batch.
  Can be used for monitoring if cf.val_mode = 'patient_val' for a monitoring closer to actualy evaluation (done in 3D),
  if willing to accept speed-loss during training.
  :return: out_batch: dictionary containing one patient with batch_size = n_3D_patches in 3D or
  batch_size = n_2D_patches in 2D .
class_docstr_tok: ["creates","a","test","generator","that","iterates","over","entire","given","dataset","returning","1","patient","per","batch",".","Can","be","used","for","monitoring","if","cf.val_mode","=","'patient_val","'","for","a","monitoring","closer","to","actualy","evaluation","(","done","in","3D",")",",","if","willing","to","accept","speed-loss","during","training",".",":","return",":","out_batch",":","dictionary","containing","one","patient","with","batch_size","=","n_3D_patches","in","3D","or","batch_size","=","n_2D_patches","in","2D","."]
code: def generate_train_batch(self):
      pid = self.dataset_pids[self.patient_ix]
      patient = self._data[pid]
      all_data = np.load(patient["data"], mmap_mode="r")
      data = all_data[0]
      seg = all_data[1].astype("uint8")
      batch_class_targets = np.array([patient["class_target"]])
  
      out_data = data[None, None]
      out_seg = seg[None, None]
  
      print("check patient data loader", out_data.shape, out_seg.shape)
      batch_2D = {
          "data": out_data,
          "seg": out_seg,
          "class_target": batch_class_targets,
          "pid": pid,
      }
      converter = ConvertSegToBoundingBoxCoordinates(
          dim=2,
          get_rois_from_seg_flag=False,
          class_specific_seg_flag=self.cf.class_specific_seg_flag,
      )
      batch_2D = converter(**batch_2D)
  
      batch_2D.update(
          {
              "patient_bb_target": batch_2D["bb_target"],
              "patient_roi_labels": batch_2D["roi_labels"],
              "original_img_shape": out_data.shape,
          }
      )
  
      self.patient_ix += 1
      if self.patient_ix == len(self.dataset_pids):
          self.patient_ix = 0
  
      return batch_2D
  
imports: import numpy
  import os
  from collections import OrderedDict
  import pandas
  import pickle
  import time
  import subprocess
  import utils.dataloader_utils
  from batchgenerators.dataloading.data_loader import SlimDataLoaderBase
  from batchgenerators.transforms.spatial_transforms import MirrorTransform
  from batchgenerators.transforms.abstract_transforms import Compose
  from batchgenerators.dataloading.multi_threaded_augmenter import MultiThreadedAugmenter
  from batchgenerators.dataloading import SingleThreadedAugmenter
  from batchgenerators.transforms.spatial_transforms import SpatialTransform
  from batchgenerators.transforms.crop_and_pad_transforms import CenterCropTransform
  from batchgenerators.transforms.utility_transforms import ConvertSegToBoundingBoxCoordinates
label_desc: Use image node_id 2 for calling the PatientBatchIterator obj's underlying member method code with example usage: obj.generate_train_batch() and returns: batch_2D