<jupyter_start><jupyter_text><jupyter_code>from keras.preprocessing.image import ImageDataGenerator
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D
from keras.layers import Activation, Dropout, Flatten, Dense
from keras import backend as K
from keras.layers.normalization import BatchNormalization
from keras import optimizers
import keras
import numpy as np
from sklearn.metrics import confusion_matrix
def random_crop(img, random_crop_size):
    assert img.shape[2] == 3
    height, width = img.shape[0], img.shape[1]
    dy, dx = random_crop_size
    x = np.random.randint(0, width - dx + 1)
    y = np.random.randint(0, height - dy + 1)
    return img[y:(y+dy), x:(x+dx), :]

%pwd
def crop_generator(batches, crop_length):
    
    while True:
        batch_x, batch_y = next(batches)
        batch_crops = np.zeros((batch_x.shape[0], crop_length, crop_length, 3))
        for i in range(batch_x.shape[0]):
            batch_crops[i] = random_crop(batch_x[i], (crop_length, crop_length))
        yield (batch_crops, batch_y)
img_width, img_height = 256, 256
 
train_data_dir = 'My Drive/Colab Notebooks/white/train'
validation_data_dir = 'y Drive/Colab Notebooks/white/test'

epochs = 1
batch_size = 100
weight_decay = 0.004  # weight decay coefficient
CROP_LENGTH   = 227
 
if K.image_data_format() == 'channels_first':
    input_shape = (3, CROP_LENGTH, CROP_LENGTH)
else:
    input_shape = (CROP_LENGTH, CROP_LENGTH, 3)
train_datagen = ImageDataGenerator(
                rescale = 1. / 255,
                 shear_range = 0.2,
                  zoom_range = 0.2,
            horizontal_flip = True)
 
test_datagen = ImageDataGenerator(rescale = 1. / 255)
 
train_generator = train_datagen.flow_from_directory(train_data_dir,
                              target_size =(img_width, img_height),
                     batch_size = batch_size, class_mode ='categorical')
 
validation_generator = test_datagen.flow_from_directory(
                                    validation_data_dir,
                   target_size =(img_width, img_height),
          batch_size = batch_size, class_mode ='categorical')

train_crops = crop_generator(train_generator, CROP_LENGTH)
valid_crops = crop_generator(validation_generator, CROP_LENGTH)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09189895470383275, 'fraction_numerical': 0.01916376306620209, 'mean_word_length': 3.375238095238095, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '317582', 'license': 'BSD-2-Clause', 'n_tokens_mistral': 799, 'n_tokens_neox': 749, 'n_words': 170, 'path': 'veridium.ipynb', 'repo_name': 'avurity/Adafruit-GFX-Library', 'size': '2296'}