Repository navigation
Expand file tree
/
Copy pathPredictions.py
More file actions
97 lines (89 loc) · 2.84 KB
/
Copy pathPredictions.py
File metadata and controls
97 lines (89 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# -*- coding: utf-8 -*-
"""
Created on Sat Aug 8 09:17:32 2020
@author: A ARUN JOSEPHRAJ
"""
# Prediction of different images
import numpy as np
import matplotlib.pyplot as plt
from tensorflow import keras
from keras.preprocessing import image
def show_images(data):
plt.axis('off')
plt.imshow(data)
plt.show()
Main_Model = keras.models.load_model('models/Main')
#predicting a single image
folder ='dataset/test_set/Kitten V Ice Cream/1 (1).jpg'
img = image.load_img(folder, target_size = (250,250))
test_image = image.load_img(folder, target_size = (250,250))
test_image = image.img_to_array(test_image) #converting it into an array
test_image = np.expand_dims(test_image, axis = 0)
result = Main_Model.predict(test_image)
result = np.round(result)
if result[0][0] == 1:
Label = "Chihuahua V Muffin"
Sub_Model = keras.models.load_model('models/ChihuahuaVMuffin')
prediction = Sub_Model(test_image)
if prediction[0][0] == 1:
title = "Chihuahua"
else:
title = "Muffin"
elif result[0][1] == 1:
Label = "Kitten V Ice Cream"
Sub_Model = keras.models.load_model('models/KittenVIceCream')
prediction = Sub_Model(test_image)
if prediction[0][0] == 1:
title = "Kitten"
else:
title = "Ice Cream"
elif result[0][2] == 1:
Label = "Labradoodle V Fried Chicken"
Sub_Model = keras.models.load_model('models/LabradoodleVFriedChicken')
prediction = Sub_Model(test_image)
if prediction[0][0] == 1:
title = "Labradoodle"
else:
title = "Fried Chicken"
elif result[0][3] == 1:
Label = "Parrot V Guacamole"
Sub_Model = keras.models.load_model('models/ParrotVGuacamole')
prediction = Sub_Model(test_image)
if prediction[0][0] == 1:
title = "Parrot"
else:
title = "Guacamole"
elif result[0][4] == 1:
Label = "Puppy V Bagel"
Sub_Model = keras.models.load_model('models/PuppyVBagel')
prediction = Sub_Model(test_image)
if prediction[0][0] == 1:
title = "Puppy"
else:
title = "Bagel"
elif result[0][5] == 1:
Label = "Sheepdog V Mop"
Sub_Model = keras.models.load_model('models/SheepdogVMop')
prediction = Sub_Model(test_image)
if prediction[0][0] == 1:
title = "Sheepdog"
else:
title = "Mop"
elif result[0][6] == 1:
Label = "Shiva Inu V Marshmallow"
Sub_Model = keras.models.load_model('models/ShivaInuVMarshmallow')
prediction = Sub_Model(test_image)
if prediction[0][0] == 1:
title = "Shiva Inu"
else:
title = "Marshmallow"
else:
Label = "Sloth V Croissant"
Sub_Model = keras.models.load_model('models/SlothVCroissant')
prediction = Sub_Model(test_image)
if prediction[0][0] == 1:
title = "Sloth"
else:
title = "Croissant"
show_images(img)
print("The image belongs to:",Label,"\nThe image is of a: ",title)