<jupyter_start><jupyter_text>Begin by creating the ipynb file in the same parent folder where the downloaded data set is kept. The CNN model should have the following layers: ● Input layer ● Convolutional layer 1 with 32 filters of kernel size[5,5] ● Pooling layer 1 with pool size[2,2] and stride 2 ● Convolutional layer 2 with 64 filters of kernel size[5,5] ● Pooling layer 2 with pool size[2,2] and stride 2 ● Dense layer whose output size is fixed in the hyper parameter: fc_size=32 ● Dropout layer with dropout probability 0.4 Predict the class by doing a softmax on the output of the dropout layers. This should be followed by training and evaluation: ● For the training step, define the loss function and minimize it ● For the evaluation step, calculate the accuracy Run the program for 100, 200, and 300 iterations, respectively. Follow this by a report on the final accuracy and loss on the evaluation data.<jupyter_code>#import all the require labraries 
import tensorflow as tf
from tensorflow import keras
from keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras import models, layers
dataflow = ImageDataGenerator(rescale = 1.0 / 255.0 )
#import training data from file 
train = dataflow.flow_from_directory('../input/dog-cat-classification/data/train', class_mode = 'categorical')
#import test data from file 
test = dataflow.flow_from_directory('../input/dog-cat-classification/data/test', class_mode = 'categorical')
#build model according to 
#Input layer ● Convolutional layer 1 with 32 filters of kernel size[5,5] 
#Pooling layer 1 with pool size[2,2] and stride
#Convolutional layer 2 with 64 filters of kernel size[5,5]
#Pooling layer 2 with pool size[2,2] and stride 2
#Dense layer whose output size is fixed in the hyper parameter: fc_size=32 
#Dropout layer with dropout probability 0.4 Predict the class by doing a softmax on the output of the dropout layers. This should be followed by training and evaluation: 
#
model = models.Sequential()
model.add( layers.Conv2D( 32, (5, 5 ), activation = 'relu', padding = 'same', input_shape = (256,  256 , 3 )))
model.add(layers.MaxPooling2D(2,2))
model.add(layers.Conv2D(64, (5, 5 ), activation = 'relu'))
model.add(layers.MaxPooling2D((2,2)))
model.add(layers.Dropout(0.4))
model.add(layers.Flatten())
model.add(layers.Dense(32, activation = 'relu'))
model.add(layers.Dense(2, activation = 'softmax'))

#For the training step, define the loss function and minimize it

sgd_opt = tf.keras.optimizers.SGD(lr = 0.001)
#compiling model 
history=model.compile( optimizer = sgd_opt, loss = 'binary_crossentropy', metrics =  ['accuracy'])
#model train for 100 epochs 
history =model.fit(train, validation_data = test, epochs =100)
test_loss, test_accuracy = model.evaluate(test)
test_loss
from matplotlib import pyplot as plt 

plt.plot(history.history['accuracy'])
plt.plot(history.history['val_accuracy'])
plt.title('Accuracy')
plt.ylabel('accuracy')
plt.xlabel('epochs')
plt.legend(['train', 'test'], loc = 'upper right')
plt.show()
history =model.fit(train, validation_data = test, epochs =200)
test_loss, test_accuracy = model.evaluate(test)
test_loss
from matplotlib import pyplot as plt 

plt.plot(history.history['accuracy'])
plt.plot(history.history['val_accuracy'])
plt.title('Accuracy')
plt.ylabel('accuracy')
plt.xlabel('epochs')
plt.legend(['train', 'test'], loc = 'upper right')
plt.show()
history =model.fit(train, validation_data = test, epochs =300)
from matplotlib import pyplot as plt 

plt.plot(history.history['accuracy'])
plt.plot(history.history['val_accuracy'])
plt.title('Accuracy')
plt.ylabel('accuracy')
plt.xlabel('epochs')
plt.legend(['train', 'test'], loc = 'upper right')
plt.show()
test_loss, test_accuracy = model.evaluate(test)
test_loss<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11149273447820343, 'fraction_numerical': 0.026948480845442536, 'mean_word_length': 5.760714285714286, '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': '547653', 'license': 'MIT', 'n_tokens_mistral': 1271, 'n_tokens_neox': 1181, 'n_words': 420, 'path': 'notebook/project-3 (1).ipynb', 'repo_name': 'Anuragbisenn/Pet-Classification-Model-Using-CNN.', 'size': '3785'}