This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x = Flatten()(vgg.output) | |
prediction = Dense(len(folders), activation='softmax')(x) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
folders = glob('Datasets/train/*') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# don't train existing weights | |
for layer in vgg.layers: | |
layer.trainable = False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vgg = VGG16(input_shape=IMAGE_SIZE + [3], weights='imagenet', include_top=False) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
train_path = 'Datasets/train' | |
valid_path = 'Datasets/test' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# re-size all the images | |
IMAGE_SIZE = [224, 224] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras.layers import Input, Lambda, Dense, Flatten | |
from keras.models import Model | |
from keras.applications.vgg16 import VGG16 | |
from keras.applications.vgg16 import preprocess_input | |
from keras.preprocessing import image | |
from keras.preprocessing.image import ImageDataGenerator | |
from keras.models import Sequential | |
import numpy as np | |
from glob import glob | |
import matplotlib.pyplot as plt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
result = cnn.predict(test_image) | |
training_set.class_indicies | |
if result[0][0] == 1 | |
prediction = 'dog' | |
else | |
prediction = 'cat' | |
print(prediction) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
from keras.preprocessing import image | |
test_image = image.load_img('dataset/prediction/image1.jpg', target_size = (64,64)) | |
test_image = image.img_to_array(test_image) | |
test_image = np.expand_dims(test_image, axis = 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cnn.fit(x = training_set, validation_data = test_set, epochs =25) |