def test_generator(x_train, img_dir, batch_size, shuffle=True):
    batch_index = 0
    n = x_train.shape[0]
    eraser = get_random_eraser(v_h=0.0)
    while 1:
        if (batch_index == 0):
            index_array = np.arange(n)
            if shuffle:
                index_array = np.random.permutation(n)
        current_index = ((batch_index * batch_size) % n)
        if (n >= (current_index + batch_size)):
            current_batch_size = batch_size
            batch_index += 1
        else:
            current_batch_size = (n - current_index)
            batch_index = 0
        batch_x = []
        batch_id = index_array[current_index:(current_index + current_batch_size)]
        for id in batch_id:
            img = cv2.imread((img_dir + '/{}'.format(x_train[id])))
            img = cv2.resize(img, (input_size, input_size))
            img = randomHueSaturationValue(img, hue_shift_limit=((- 5), 5), sat_shift_limit=((- 1), 1), val_shift_limit=((- 2), 2), u=0.5)
            img = randomShiftScaleRotate(img, shift_limit=((- 0.2), 0.2), scale_limit=((- 0.2), 0.2), rotate_limit=((- 30), 30), aspect_limit=((- 0.2), 0.2), u=0.5)
            img = randomHorizontalFlip(img)
            batch_x.append(img)
        batch_x = (np.array(batch_x, np.float32) / 255)
        (yield batch_x)
def test_generator(x_train, img_dir, batch_size, shuffle=True):
    batch_index = 0
    n = x_train.shape[0]
    eraser = get_random_eraser(v_h=0.0)
    while 1:
        if (batch_index == 0):
            index_array = np.arange(n)
            if shuffle:
                index_array = np.random.permutation(n)
        current_index = ((batch_index * batch_size) % n)
        if (n >= (current_index + batch_size)):
            current_batch_size = batch_size
            batch_index += 1
        else:
            current_batch_size = (n - current_index)
            batch_index = 0
        batch_x = []
        batch_id = index_array[current_index:(current_index + current_batch_size)]
        for id in batch_id:
            img = cv2.imread((img_dir + '/{}'.format(x_train[id])))
            img = cv2.resize(img, (input_size, input_size))
            img = randomHueSaturationValue(img, hue_shift_limit=((- 5), 5), sat_shift_limit=((- 1), 1), val_shift_limit=((- 2), 2), u=0.5)
            img = randomShiftScaleRotate(img, shift_limit=((- 0.2), 0.2), scale_limit=((- 0.2), 0.2), rotate_limit=((- 30), 30), aspect_limit=((- 0.2), 0.2), u=0.5)
            img = randomHorizontalFlip(img)
            batch_x.append(img)
        batch_x = (np.array(batch_x, np.float32) / 255)
        (yield batch_x)