<jupyter_start><jupyter_text>Importing Packages<jupyter_code>from pyimagesearch.io import Hdf5DatasetLoader
from tensorflow.keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img
from sklearn.model_selection import train_test_split
from config import config
import skimage
import numpy as np
import matplotlib.pyplot as plt
BATCH_SIZE = 32
from config import config

loader = Hdf5DatasetLoader()
X_train, y_train = loader.load(config.GLP_HDF5, shuffle=True, max_items=100)
def preprocess(image):
    image = np.array(image)
    image = skimage.transform.resize(image, (config.IMAGE_HEIGHT, config.IMAGE_WIDTH))
    return image

data_gen = ImageDataGenerator(
    rescale=1./255,
    rotation_range=25,
    width_shift_range=0.10,
    height_shift_range=0.10,
    zoom_range=[1.0, 1.5],
    #shear_range=1.5,
    brightness_range=[0.1, 1.0],
    fill_mode='nearest',
    horizontal_flip=False,
    validation_split=0.2)

X_train = np.asarray([image.reshape(32, 151, 1) for image in X_train])
X_train = np.asarray([skimage.transform.resize(image, (config.IMAGE_HEIGHT, config.IMAGE_WIDTH)) for image in X_train])
images, labels = next(data_gen.flow(X_train, y_train, batch_size=BATCH_SIZE))
#images = np.asarray([skimage.transform.resize(image, (config.IMAGE_HEIGHT, config.IMAGE_WIDTH)) for image in images])

print (images.shape)

def plotImages(images_arr, labels, rows, columns):
    fig, axes = plt.subplots(rows, columns, figsize=(50,50))
    axes = axes.flatten()
    for img, label, ax in zip(images_arr, labels, axes):
        img = np.squeeze(img, axis=(2,))
        ax.set_title(label)
        ax.imshow(img, cmap='gray')
    plt.tight_layout()
    plt.show()
    
plotImages(images, labels, int(BATCH_SIZE / 4), 4)<jupyter_output>(32, 64, 128, 1)
{'fraction_non_alphanumeric': 0.11886160714285714, 'fraction_numerical': 0.029575892857142856, 'mean_word_length': 4.996655518394649, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '117445', 'license': 'MIT', 'n_tokens_mistral': 668, 'n_tokens_neox': 635, 'n_words': 134, 'path': 'keras_datagenerator.ipynb', 'repo_name': 'aboerzel/ANPR-keras', 'size': '1792'}