<jupyter_start><jupyter_text>Importing libraries<jupyter_code>import tensorflow as tf
from keras.preprocessing.image import ImageDataGenerator
tf.__version__<jupyter_output><empty_output><jupyter_text>Data Preprocessing  Preprocessing the Training set<jupyter_code># Image Augmentation (applying some geometrical transformations on the images to avoid overfitting)

train_datagen = ImageDataGenerator(rescale=1./255, shear_range=0.2, zoom_range=0.2, horizontal_flip=True)

training_set = train_datagen.flow_from_directory('dataset/training_set', target_size=(64, 64), batch_size=32, class_mode='binary')<jupyter_output>Found 8000 images belonging to 2 classes.<jupyter_text>Preprocessing the Test set<jupyter_code>test_datagen = ImageDataGenerator(rescale=1./255)

test_set = test_datagen.flow_from_directory('dataset/test_set', target_size=(64, 64), batch_size=32, class_mode='binary')<jupyter_output>Found 2000 images belonging to 2 classes.<jupyter_text>Building the CNN<jupyter_code># Creates cnn object and initializes it as a sequence of layers

cnn = tf.keras.models.Sequential()<jupyter_output><empty_output><jupyter_text>Adding the first Convolution Layer and Pooling<jupyter_code>cnn.add(tf.keras.layers.Conv2D(filters=32, kernel_size=3, activation='relu', input_shape=[64,64,3]))
# Max Pooling

cnn.add(tf.keras.layers.MaxPool2D(pool_size=2, strides=2))<jupyter_output><empty_output><jupyter_text>Adding the second Convolution Layer and Pooling<jupyter_code>cnn.add(tf.keras.layers.Conv2D(filters=32, kernel_size=3, activation='relu'))
cnn.add(tf.keras.layers.MaxPool2D(pool_size=2, strides=2))<jupyter_output><empty_output><jupyter_text>Flattening<jupyter_code>cnn.add(tf.keras.layers.Flatten())<jupyter_output><empty_output><jupyter_text>Full Connection<jupyter_code># Adding a fully connected layer that will have flattened vector as its input
cnn.add(tf.keras.layers.Dense(units=128, activation='relu'))<jupyter_output><empty_output><jupyter_text>Output Layer<jupyter_code>cnn.add(tf.keras.layers.Dense(units=1, activation='sigmoid'))<jupyter_output><empty_output><jupyter_text>Training the CNN  Compiling the CNN<jupyter_code>cnn.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])<jupyter_output><empty_output><jupyter_text>Training the CNN and evaluating on the Test set<jupyter_code>cnn.fit(x = training_set, validation_data = test_set, epochs = 25)<jupyter_output>WARNING:tensorflow:sample_weight modes were coerced from
  ...
    to  
  ['...']
WARNING:tensorflow:sample_weight modes were coerced from
  ...
    to  
  ['...']
Train for 250 steps, validate for 63 steps
Epoch 1/25
250/250 [==============================] - 62s 250ms/step - loss: 0.6476 - accuracy: 0.6160 - val_loss: 0.5892 - val_accuracy: 0.6900
Epoch 2/25
250/250 [==============================] - 60s 239ms/step - loss: 0.5773 - accuracy: 0.7025 - val_loss: 0.5558 - val_accuracy: 0.7235
Epoch 3/25
250/250 [==============================] - 60s 239ms/step - loss: 0.5437 - accuracy: 0.7231 - val_loss: 0.5181 - val_accuracy: 0.7465
Epoch 4/25
250/250 [==============================] - 60s 241ms/step - loss: 0.5168 - accuracy: 0.7421 - val_loss: 0.4855 - val_accuracy: 0.7600
Epoch 5/25
250/250 [==============================] - 61s 243ms/step - loss: 0.4946 - accuracy: 0.7592 - val_loss: 0.5063 - val_accuracy: 0.7640
Epoch 6/25
250/250 [==============================] - 60s 239ms/step[...]<jupyter_text>* **The model gets an accuracy of 90.82% on the Training Set*** **The model gets an accuracy of 78.85% on the Test Set**  Making a single prediction<jupyter_code>import numpy as np
from keras.preprocessing import image
training_set.class_indices
# Importing the test image
test_image1 = image.load_img('dataset/single_prediction/cat_or_dog_1.jpg', target_size = (64,64))

test_image1 = image.img_to_array(test_image1)

test_image1 = np.expand_dims(test_image1, axis=0)

# Predicting the result
result = cnn.predict(test_image1)

if result[0][0]==1:
    prediction = 'DOG'
else:
    prediction = 'CAT'
print('The image is of a',prediction,'!!!')<jupyter_output>The image is of a DOG !!!
{'fraction_non_alphanumeric': 0.1602626459143969, 'fraction_numerical': 0.06590466926070039, 'mean_word_length': 6.804554079696395, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 45, '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': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '198867', 'license': 'Apache-2.0', 'n_tokens_mistral': 1644, 'n_tokens_neox': 1438, 'n_words': 294, 'path': 'ImageClassification.ipynb', 'repo_name': 'sumitkumar109/Image-Classification-Cats-vs-Dogs', 'size': '4112'}