def train_generator(x_train, y_train, img_dir, batch_size, shuffle=True):
    y_train = np.eye(55)[y_train]
    batch_index = 0
    n = x_train.shape[0]
    eraser = get_random_eraser(v_h=0.0)
    pool = Pool()
    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_id = index_array[current_index:(current_index + current_batch_size)]
        batch_x = pool.map(load_img, [(img_dir + '/{}'.format(x_train[id])) for id in batch_id])
        for id in range(len(batch_x)):
            img = batch_x[id]
            img = eraser(img)
            batch_x[id] = img
        batch_x = (np.array(batch_x, np.float32) / 255)
        batch_y = y_train[index_array[current_index:(current_index + current_batch_size)]]
        (yield (batch_x, batch_y))
def train_generator(x_train, y_train, img_dir, batch_size, shuffle=True):
    y_train = np.eye(55)[y_train]
    batch_index = 0
    n = x_train.shape[0]
    eraser = get_random_eraser(v_h=0.0)
    pool = Pool()
    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_id = index_array[current_index:(current_index + current_batch_size)]
        batch_x = pool.map(load_img, [(img_dir + '/{}'.format(x_train[id])) for id in batch_id])
        for id in range(len(batch_x)):
            img = batch_x[id]
            img = eraser(img)
            batch_x[id] = img
        batch_x = (np.array(batch_x, np.float32) / 255)
        batch_y = y_train[index_array[current_index:(current_index + current_batch_size)]]
        (yield (batch_x, batch_y))