-
Notifications
You must be signed in to change notification settings - Fork 0
/
predict.py
37 lines (28 loc) · 893 Bytes
/
predict.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Mar 20 18:45:05 2020
@author: sudhanshukumar
"""
import numpy as np
from keras.models import load_model
from keras.preprocessing import image
class dogcat:
def __init__(self,filename):
self.filename =filename
def predictiondogcat(self):
# load model
model = load_model('model.h5')
# summarize model
#model.summary()
imagename = self.filename
test_image = image.load_img(imagename, target_size = (64, 64))
test_image = image.img_to_array(test_image)
test_image = np.expand_dims(test_image, axis = 0)
result = model.predict(test_image)
if result[0][0] == 1:
prediction = 'dog'
return [{ "image" : prediction}]
else:
prediction = 'cat'
return [{ "image" : prediction}]