class_docstr: Batches are sampled from sorted buckets of data.
  First, partition data in buckets of size `batch_size * mult`.
  Each bucket contains `batch_size * mult` elements. The samples inside each bucket are sorted
  based on sort_key and then batched.
  Parameters
  ----------
  sort_keys : list-like object
      The keys to sort the samples.
  batch_size : int
      Batch size of the sampler.
  mult : int or float, default 100
      The multiplier to determine the bucket size. Each bucket will have size `mult * batch_size`.
  num_parts: int, default 1
    Number of partitions which the data is split into
  part_index: int, default 0
    The index of the part to read from
  shuffle : bool, default False
      Whether to shuffle the data.
  Examples
  --------
  >>> lengths = [np.random.randint(1, 1000) for _ in range(1000)]
  >>> sampler = gluoncv.data.SplitSortedBucketSampler(lengths, 16, 1000)
  >>> # The sequence lengths within the batch will be sorted
  >>> for i, indices in enumerate(sampler):
  ...     if i == 0:
  ...         print([lengths[ele] for ele in indices])
  [-etc-]
class_docstr_tok: ["Batches","are","sampled","from","sorted","buckets","of","data",".","First",",","partition","data","in","buckets","of","size","`","batch_size","*","mult","`",".","Each","bucket","contains","`","batch_size","*","mult","`","elements",".","The","samples","inside","each","bucket","are","sorted","based","on","sort_key","and","then","batched",".","Parameters","--","--","--","--","--","sort_keys",":","list-like","object","The","keys","to","sort","the","samples",".","batch_size",":","int","Batch","size","of","the","sampler",".","mult",":","int","or","float",",","default","100","The","multiplier","to","determine","the","bucket","size",".","Each","bucket","will","have","size","`","mult","*","batch_size","`",".","num_parts",":","int",",","default","1","Number","of","partitions","which","the","data","is","split","into","part_index",":","int",",","default","0","The","index","of","the","part","to","read","from","shuffle",":","bool",",","default","False","Whether","to","shuffle","the","data",".","Examples","--","--","--","--",">",">",">","lengths","=","[","np.random.randint","(","1",",","1000",")","for","_","in","range","(","1000",")","]",">",">",">","sampler","=","gluoncv.data.SplitSortedBucketSampler","(","lengths",",","16",",","1000",")",">",">",">","#","The","sequence","lengths","within","the","batch","will","be","sorted",">",">",">","for","i",",","indices","in","enumerate","(","sampler",")",":","...","if","i","==","0",":","...","print","(","[","lengths","[","ele","]","for","ele","in","indices","]",")","[","-etc-","]"]
code: def __iter__(self):
      if self._num_parts > 1:
          self._shuffled_ids = np.random.RandomState(
              seed=self._seed
          ).permutation(self._shuffled_ids)
      if self._shuffle:
          sample_ids = np.random.permutation(
              self._shuffled_ids[self._start : self._end]
          )
      else:
          sample_ids = list(range(self._start, self._end))
      bucket_size = int(self._mult * self._batch_size)
      for bucket_begin in range(0, len(sample_ids), bucket_size):
          bucket_end = min(bucket_begin + bucket_size, len(sample_ids))
          if bucket_end - bucket_begin < self._batch_size:
              bucket_begin = bucket_end - self._batch_size
          sorted_sample_ids = sorted(
              sample_ids[bucket_begin:bucket_end],
              key=lambda i: self._sort_keys[i],
              reverse=random.randint(0, 1),
          )
          batch_begins = list(
              range(0, len(sorted_sample_ids), self._batch_size)
          )
          if self._shuffle:
              np.random.shuffle(batch_begins)
          for batch_begin in batch_begins:
              batch_end = min(
                  batch_begin + self._batch_size, len(sorted_sample_ids)
              )
              if batch_end - batch_begin < self._batch_size:
                  yield sorted_sample_ids[
                      batch_end - self._batch_size : batch_end
                  ]
              else:
                  yield sorted_sample_ids[batch_begin:batch_end]
  
file_path: gluon-cv/gluoncv/data/sampler.py
imports: import random
  import numpy
  from mxnet import gluon
label_desc: Use image node_id 2 for calling the SplitSortedBucketSampler obj's underlying member method code with example usage: obj.__iter__() without return types