forked from SaumilShah66/dogs-cat-classifier
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapply.py
63 lines (49 loc) · 1.78 KB
/
apply.py
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
from __future__ import division, print_function, absolute_import
import numpy as np
import tflearn
from tflearn.data_utils import shuffle, to_categorical
from tflearn.layers.core import input_data, dropout, fully_connected
from tflearn.layers.conv import conv_2d, max_pool_2d
from tflearn.layers.estimator import regression
import cv2
#Creating and loading trained model
#---------------------------------------------------------
network = input_data(shape=[None, 50, 50, 1])
network = conv_2d(network, 30, 3, activation='relu')
network = max_pool_2d(network, 2)
network = conv_2d(network, 30, 3, activation='relu')
network = max_pool_2d(network, 2)
network = conv_2d(network, 40, 3, activation='relu')
network = max_pool_2d(network, 2)
network = conv_2d(network, 40, 3, activation='relu')
network = max_pool_2d(network, 2)
network = conv_2d(network, 40, 3, activation='relu')
network = max_pool_2d(network, 2)
network = conv_2d(network, 30, 3, activation='relu')
network = max_pool_2d(network, 2)
network = fully_connected(network, 100, activation='relu')
network = dropout(network, 0.5)
network = fully_connected(network, 50, activation='relu')
network = fully_connected(network, 2, activation='softmax')
network = regression(network)
model = tflearn.DNN(network)
print('Model has been created')
print('Loading the network')
model.load('my_cnn.tflearn')
print('Network loaded')
#-------------------------------------------------------
#Loading image
print('Loading an image')
image_name = 'cats/cat.11737.jpg'
img = cv2.imread(image_name,0)
img = cv2.resize(img,(50,50))
# Making prediction
print('Making prediction')
img = np.reshape(img,(-1,50,50,1))
predict = model.predict(img)
if pre[0][0] >= 0.5:
print("It's a Dog")
elif pre[0][1] >= 0.5:
print("It's a Cat")
else:
print("I can't predict")