<jupyter_start><jupyter_text><jupyter_code>from google.colab import drive
drive.mount('/content/drive')
#Data Augmentation using Python and keras
from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img
#load_img-- imp property as it loads the img we want and help to generate the date we need 

datagen= ImageDataGenerator(
    rotation_range=40,#a value in degrees (0-180), a range within which to randomly rotate pictures
    width_shift_range=0.2,#ranges (as a fraction of total width or height) 
    height_shift_range=0.2,#within which to randomly translate pictures vertically or horizontally
    shear_range=0.2,#for randomly applying shearing transformations
    zoom_range=0.2,#for randomly zooming inside pictures
    horizontal_flip=True,#randomly flipping half of the images horizontally --relevant when there are 
                          #no assumptions of horizontal assymetry (e.g. real-world pictures)
    fill_mode='nearest'# strategy used for filling in newly created pixels, which can appear 
                      #after a rotation or a width/height shift.
)


img= load_img('/content/drive/My Drive/Colab Notebooks/CNN CatVsDog/cat-vs-dog.jpg')#this is a PIL image
x = img_to_array(img) #this is a Numpy array with shape(3,150, 150)
x = x.reshape((1,)+ x.shape)#this is a Numpy array with shape(1,3,150,150)

## the .flow() command below generates batches of randomly transformed images
# and saves the results to the `preview/` directory
i=0
for batch in datagen.flow(x,batch_size=1, save_to_dir='/content/drive/My Drive/Colab Notebooks/CNN CatVsDog/preview', save_prefix='cat', save_format='jpg'):
  i+=1
  if i>20:
    break #otherwise the generator would go loop imdefinately<jupyter_output><empty_output><jupyter_text>Create CNN Module n Optimize it using Keras Tuner<jupyter_code><jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08466453674121406, 'fraction_numerical': 0.01863684771033014, 'mean_word_length': 4.693939393939394, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '45151', 'license': 'MIT', 'n_tokens_mistral': 602, 'n_tokens_neox': 554, 'n_words': 193, 'path': 'CNN_cat_vs_dog.ipynb', 'repo_name': 'ArpitaChatterjee/CNN-Data-Augmentation', 'size': '1878'}