<jupyter_start><jupyter_text>Importing the Libraries<jupyter_code>import tensorflow as tf
from keras.preprocessing.image import ImageDataGenerator
import os
tf.__version__<jupyter_output><empty_output><jupyter_text>Part 1 - Data Preprocessing  Generating images for the Training set<jupyter_code>train_datagen = ImageDataGenerator(rescale = 1./255,
                                   shear_range = 0.2,
                                   zoom_range = 0.2,
                                   horizontal_flip = True)<jupyter_output><empty_output><jupyter_text>Generating images for the Test set<jupyter_code>test_datagen = ImageDataGenerator(rescale = 1./255)<jupyter_output><empty_output><jupyter_text>Creating the Training set<jupyter_code># path to training set 
trainingDir = '../dataSet/trainAlgoData'
training_set = train_datagen.flow_from_directory(trainingDir,                                
                                                 target_size = (128, 128),
                                                 batch_size = 10,
                                                 color_mode = 'grayscale',                                
                                                 class_mode = 'categorical')
test_set = test_datagen.flow_from_directory('../dataSet/testAlgoData',
                                            target_size = (128, 128),                                  
                                            batch_size = 3,        
                                            color_mode = 'grayscale',
                                            class_mode = 'categorical')<jupyter_output>Found 15 images belonging to 2 classes.<jupyter_text>Part 2 - Building the CNN  Initializing the CNN<jupyter_code>classifier = tf.keras.models.Sequential()<jupyter_output><empty_output><jupyter_text>Step 1 - Convolution<jupyter_code>classifier.add(tf.keras.layers.Conv2D(filters=32,
                                     kernel_size=3, 
                                     padding="same", 
                                     activation="relu", 
                                     input_shape=[128, 128, 1]))<jupyter_output><empty_output><jupyter_text>Step 2 - Pooling<jupyter_code>classifier.add(tf.keras.layers.MaxPool2D(pool_size=2, 
                                         strides=2, 
                                         padding='valid'))<jupyter_output><empty_output><jupyter_text>Adding a second convolutional layer<jupyter_code>classifier.add(tf.keras.layers.Conv2D(filters=32, 
                                      kernel_size=3, 
                                      padding="same", 
                                      activation="relu"))

classifier.add(tf.keras.layers.MaxPool2D(pool_size=2, 
                                         strides=2, 
                                         padding='valid'))<jupyter_output><empty_output><jupyter_text>Step 3 - Flattening<jupyter_code>classifier.add(tf.keras.layers.Flatten())<jupyter_output><empty_output><jupyter_text>Step 4 - Full Connection<jupyter_code>classifier.add(tf.keras.layers.Dense(units=128, 
                                     activation='relu'))
classifier.add(tf.keras.layers.Dropout(0.40))
classifier.add(tf.keras.layers.Dense(units=96, activation='relu'))
classifier.add(tf.keras.layers.Dropout(0.40))
classifier.add(tf.keras.layers.Dense(units=64, activation='relu'))
classifier.add(tf.keras.layers.Dense(units=2, activation='softmax')) # softmax for more than 27<jupyter_output><empty_output><jupyter_text>Part 3 - Training the CNN  Compiling the CNN<jupyter_code>classifier.compile(optimizer = 'adam', 
                   loss = 'categorical_crossentropy', 
                   metrics = ['accuracy'])<jupyter_output><empty_output><jupyter_text>Training the CNN on the Training set and evaluating it on the Test set<jupyter_code>classifier.summary()
classifier.fit(training_set,
                  epochs = 10,
                  validation_data = test_set)<jupyter_output>Epoch 1/10
23/23 [==============================] - 1s 43ms/step - loss: 0.7376 - accuracy: 0.5556 - val_loss: 0.6364 - val_accuracy: 0.2667
Epoch 2/10
23/23 [==============================] - 1s 40ms/step - loss: 0.3589 - accuracy: 0.8978 - val_loss: 0.0045 - val_accuracy: 1.0000
Epoch 3/10
23/23 [==============================] - 1s 40ms/step - loss: 0.1059 - accuracy: 0.9733 - val_loss: 1.4148e-04 - val_accuracy: 1.0000
Epoch 4/10
23/23 [==============================] - 1s 40ms/step - loss: 0.0741 - accuracy: 0.9822 - val_loss: 2.8184e-04 - val_accuracy: 1.0000
Epoch 5/10
23/23 [==============================] - 1s 39ms/step - loss: 0.0698 - accuracy: 0.9822 - val_loss: 7.3348e-05 - val_accuracy: 1.0000
Epoch 6/10
23/23 [==============================] - 1s 40ms/step - loss: 0.0692 - accuracy: 0.9956 - val_loss: 6.2329e-04 - val_accuracy: 1.0000
Epoch 7/10
23/23 [==============================] - 1s 39ms/step - loss: 0.0325 - accuracy: 0.9911 - val_loss: 1.0734e-04 - val_accuracy: [...]<jupyter_text>Saving the Model<jupyter_code>model_json = classifier.to_json()
with open("model_new.json", "w") as json_file:
    json_file.write(model_json)
print('Model Saved')
classifier.save_weights('model_new.h5')
print('Weights saved')<jupyter_output>Model Saved
Weights saved
{'fraction_non_alphanumeric': 0.14085308056872037, 'fraction_numerical': 0.05535545023696682, 'mean_word_length': 2.1937046004842613, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 35, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '177152', 'license': 'MIT', 'n_tokens_mistral': 1795, 'n_tokens_neox': 1547, 'n_words': 260, 'path': 'Models/Model.ipynb', 'repo_name': 'Jdreioe/AAC_Plus', 'size': '5275'}