text: import numpy as np
  import yaml
  from lib.SSH_pytorch.model.utils.config import cfg
  from lib.SSH_pytorch.model.roi_data_layer.minibatch import get_minibatch
  
  class RoIDataLayer(object):
      def __init__(self, roidb, num_classes):
          """Set the roidb to be used by this layer during training."""
          self._roidb = roidb
          self._num_classes = num_classes
          self._shuffle_roidb_inds()
  
      def _shuffle_roidb_inds(self, gpu_id=0):
          self.gpu_id = gpu_id
          """Randomly permute the training roidb."""
          if cfg.TRAIN.ASPECT_GROUPING:
              widths = np.array([r['width'] for r in self._roidb])
              heights = np.array([r['height'] for r in self._roidb])
              horz = (widths >= heights)
              vert = np.logical_not(horz)
              horz_inds = np.where(horz)[0]
              vert_inds = np.where(vert)[0]
              inds = np.hstack((
                  np.random.permutation(horz_inds),
                  np.random.permutation(vert_inds)))
              inds = np.reshape(inds, (-1, 2))
              np.random.seed(gpu_id)
              row_perm = np.random.permutation(np.arange(inds.shape[0]))
              inds = np.reshape(inds[row_perm, :], (-1,))
              self._perm = inds
          else:
              self._perm = np.random.permutation(np.arange(len(self._roidb)))
          self._cur = 0
  
      def _get_next_minibatch_inds(self):
          """Return the roidb indices for the next minibatch."""
          if self._cur + cfg.TRAIN.IMS_PER_BATCH >= len(self._roidb):
              self._shuffle_roidb_inds(self.gpu_id)
  
          db_inds = self._perm[self._cur:self._cur + cfg.TRAIN.IMS_PER_BATCH]
          self._cur += cfg.TRAIN.IMS_PER_BATCH
          return db_inds
  
      def _get_next_minibatch(self):
          """Return the blobs to be used for the next minibatch.
          """
          db_inds = self._get_next_minibatch_inds()
          minibatch_db = [self._roidb[i] for i in db_inds]
          return get_minibatch(minibatch_db)
  
      def set_roidb(self, roidb, gpu_id=0):
          """Set the roidb to be used by this layer during training."""
          self._roidb = roidb
          self._shuffle_roidb_inds(gpu_id)
  
      def forward(self):
          """Get blobs and copy them into this layer's top blob vector."""
          blobs = self._get_next_minibatch()
          return blobs