Question: answer the questions and print the output with the solution and Screen Shot The output and the code I want picture Screen Shot. To do

answer the questions and print the output with the solution and Screen Shot The output and the code I want picture Screen Shot. To do this, you will need a data set to train the model. The data set for this lab can be obtained from GitHub repository. You can download it from here
Search in goog-le nickmccullub / cats-and-dogs git-hub
Here's what the repository contains:
A folder called training_data that holds 4000 images of cats and 4000 images of dogs
A folder called test_data that contains 1000 images of cats and 1000 images of dogs
A folder called predictions that 1 image of a cat and 1 image of a dog. We will use the images in this predictions folder to make single predictions using our trained model later in this tutorial.
Every image in this data set is a .jpg file.
The code
import numpy as np
import tensorflow as tf
from tensorflow.keras.preprocessing.image import ImageDataGenerator
training_generator = ImageDataGenerator(
rescale =1/255,
shear_range =0.2,
zoom_range =0.2,
horizontal_flip = True)
training_set = training_generator.flow_from_directory('training_data',
target_size =(64,64),
batch_size =32,
class_mode = 'binary')
test_generator = ImageDataGenerator(rescale =1./255)
test_set = test_generator.flow_from_directory('test_data',
target_size =(64,64),
batch_size =32,
class_mode = 'binary')
cnn = tf.keras.models.Sequential()
cnn.add(tf.keras.layers.Conv2D(filters=32, kernel_size=3, activation='relu', input_shape=[64,64,3]))
cnn.add(tf.keras.layers.MaxPool2D(pool_size=2, strides=2))
cnn.add(tf.keras.layers.Conv2D(filters=32, kernel_size=3, activation='relu'))
cnn.add(tf.keras.layers.MaxPool2D(pool_size=2, strides=2))
cnn.add(tf.keras.layers.Flatten())
cnn.add(tf.keras.layers.Dense(units=128, activation=relu))
cnn.add(tf.keras.layers.Dense(units=1, activation='sigmoid'))
cnn.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics =['accuracy'])
cnn.fit(x = training_set, validation_data = test_set, epochs =10)
from tensorflow.keras.preprocessing import image
test_image_1= image.load_img('predictions/cat_or_dog_1.jpg', target_size =(64,64))
test_image_2= image.load_img('predictions/cat_or_dog_2.jpg', target_size =(64,64))
test_image_1= image.img_to_array(test_image_1)
test_image_2= image.img_to_array(test_image_2)
test_image_1= np.expand_dims(test_image_1, axis =0)
test_image_2= np.expand_dims(test_image_2, axis =0)
print(cnn.predict(test_image_1))
print(cnn.predict(test_image_2))
questions
Please print the output of training_generator.flow_from_directory as an image here [1 Mark]
Please print the output of test_generator.flow_from_directory as an image here [1 Mark]
What will be the add command if we wanted to have 64 feature detectors, with a kernel size of 5x5[2 Marks]
What will be the add command if we wanted to have a max pooling layer which reduces the size of the image by a factor of 4?[2 Marks]
Please share the output of the first, fifth and tenth epoch of training as an image here [2 marks]
print(cnn.predict(test_image_1)) and
print(cnn.predict(test_image_2))
What is the output

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!