def __init__(self, batch_size, data_shape, label_width=1, path_imgrec=None, path_imglist=None, path_root=None, path_imgidx=None, shuffle=False, part_index=0, num_parts=1, aug_list=None, imglist=None, data_name='data', label_name='softmax_label', dtype='float32', last_batch_handle='pad', **kwargs):
    super(ImageIter, self).__init__()
    assert (path_imgrec or path_imglist or isinstance(imglist, list))
    assert (dtype in ['int32', 'float32', 'int64', 'float64']), (dtype + ' label not supported')
    num_threads = os.environ.get('MXNET_CPU_WORKER_NTHREADS', 1)
    logging.info('Using %s threads for decoding...', str(num_threads))
    logging.info('Set enviroment variable MXNET_CPU_WORKER_NTHREADS to a larger number to use more threads.')
    class_name = self.__class__.__name__
    if path_imgrec:
        logging.info('%s: loading recordio %s...', class_name, path_imgrec)
        if path_imgidx:
            self.imgrec = recordio.MXIndexedRecordIO(path_imgidx, path_imgrec, 'r')
            self.imgidx = list(self.imgrec.keys)
        else:
            self.imgrec = recordio.MXRecordIO(path_imgrec, 'r')
            self.imgidx = None
    else:
        self.imgrec = None
    if path_imglist:
        logging.info('%s: loading image list %s...', class_name, path_imglist)
        with open(path_imglist) as fin:
            imglist = {}
            imgkeys = []
            for line in iter(fin.readline, ''):
                line = line.strip().split('\t')
                label = nd.array(line[1:(- 1)], dtype=dtype)
                key = int(line[0])
                imglist[key] = (label, line[(- 1)])
                imgkeys.append(key)
            self.imglist = imglist
    elif isinstance(imglist, list):
        logging.info('%s: loading image list...', class_name)
        result = {}
        imgkeys = []
        index = 1
        for img in imglist:
            key = str(index)
            index += 1
            if (len(img) > 2):
                label = nd.array(img[:(- 1)], dtype=dtype)
            elif isinstance(img[0], numeric_types):
                label = nd.array([img[0]], dtype=dtype)
            else:
                label = nd.array(img[0], dtype=dtype)
            result[key] = (label, img[(- 1)])
            imgkeys.append(str(key))
        self.imglist = result
    else:
        self.imglist = None
    self.path_root = path_root
    self.check_data_shape(data_shape)
    self.provide_data = [(data_name, ((batch_size,) + data_shape))]
    if (label_width > 1):
        self.provide_label = [(label_name, (batch_size, label_width))]
    else:
        self.provide_label = [(label_name, (batch_size,))]
    self.batch_size = batch_size
    self.data_shape = data_shape
    self.label_width = label_width
    self.shuffle = shuffle
    if (self.imgrec is None):
        self.seq = imgkeys
    elif (shuffle or (num_parts > 1)):
        assert (self.imgidx is not None)
        self.seq = self.imgidx
    else:
        self.seq = None
    if (num_parts > 1):
        assert (part_index < num_parts)
        N = len(self.seq)
        C = (N // num_parts)
        self.seq = self.seq[(part_index * C):((part_index + 1) * C)]
    if (aug_list is None):
        self.auglist = CreateAugmenter(data_shape, **kwargs)
    else:
        self.auglist = aug_list
    self.cur = 0
    self._allow_read = True
    self.last_batch_handle = last_batch_handle
    self.num_image = (len(self.seq) if (self.seq is not None) else None)
    self._cache_data = None
    self._cache_label = None
    self._cache_idx = None
    self.reset()
def __init__(self, batch_size, data_shape, label_width=1, path_imgrec=None, path_imglist=None, path_root=None, path_imgidx=None, shuffle=False, part_index=0, num_parts=1, aug_list=None, imglist=None, data_name='data', label_name='softmax_label', dtype='float32', last_batch_handle='pad', **kwargs):
    super(ImageIter, self).__init__()
    assert (path_imgrec or path_imglist or isinstance(imglist, list))
    assert (dtype in ['int32', 'float32', 'int64', 'float64']), (dtype + ' label not supported')
    num_threads = os.environ.get('MXNET_CPU_WORKER_NTHREADS', 1)
    logging.info('Using %s threads for decoding...', str(num_threads))
    logging.info('Set enviroment variable MXNET_CPU_WORKER_NTHREADS to a larger number to use more threads.')
    class_name = self.__class__.__name__
    if path_imgrec:
        logging.info('%s: loading recordio %s...', class_name, path_imgrec)
        if path_imgidx:
            self.imgrec = recordio.MXIndexedRecordIO(path_imgidx, path_imgrec, 'r')
            self.imgidx = list(self.imgrec.keys)
        else:
            self.imgrec = recordio.MXRecordIO(path_imgrec, 'r')
            self.imgidx = None
    else:
        self.imgrec = None
    if path_imglist:
        logging.info('%s: loading image list %s...', class_name, path_imglist)
        with open(path_imglist) as fin:
            imglist = {}
            imgkeys = []
            for line in iter(fin.readline, ):
                line = line.strip().split('\t')
                label = nd.array(line[1:(- 1)], dtype=dtype)
                key = int(line[0])
                imglist[key] = (label, line[(- 1)])
                imgkeys.append(key)
            self.imglist = imglist
    elif isinstance(imglist, list):
        logging.info('%s: loading image list...', class_name)
        result = {}
        imgkeys = []
        index = 1
        for img in imglist:
            key = str(index)
            index += 1
            if (len(img) > 2):
                label = nd.array(img[:(- 1)], dtype=dtype)
            elif isinstance(img[0], numeric_types):
                label = nd.array([img[0]], dtype=dtype)
            else:
                label = nd.array(img[0], dtype=dtype)
            result[key] = (label, img[(- 1)])
            imgkeys.append(str(key))
        self.imglist = result
    else:
        self.imglist = None
    self.path_root = path_root
    self.check_data_shape(data_shape)
    self.provide_data = [(data_name, ((batch_size,) + data_shape))]
    if (label_width > 1):
        self.provide_label = [(label_name, (batch_size, label_width))]
    else:
        self.provide_label = [(label_name, (batch_size,))]
    self.batch_size = batch_size
    self.data_shape = data_shape
    self.label_width = label_width
    self.shuffle = shuffle
    if (self.imgrec is None):
        self.seq = imgkeys
    elif (shuffle or (num_parts > 1)):
        assert (self.imgidx is not None)
        self.seq = self.imgidx
    else:
        self.seq = None
    if (num_parts > 1):
        assert (part_index < num_parts)
        N = len(self.seq)
        C = (N // num_parts)
        self.seq = self.seq[(part_index * C):((part_index + 1) * C)]
    if (aug_list is None):
        self.auglist = CreateAugmenter(data_shape, **kwargs)
    else:
        self.auglist = aug_list
    self.cur = 0
    self._allow_read = True
    self.last_batch_handle = last_batch_handle
    self.num_image = (len(self.seq) if (self.seq is not None) else None)
    self._cache_data = None
    self._cache_label = None
    self._cache_idx = None
    self.reset()