guru001 commited on
Commit
b388df6
1 Parent(s): e99a146

model files added

Browse files
cnn_model.ckpt.data-00000-of-00001 ADDED
Binary file (15.4 kB). View file
 
cnn_model.ckpt.index ADDED
Binary file (557 Bytes). View file
 
cnn_model.ckpt.meta ADDED
Binary file (50.1 kB). View file
 
cnn_model.data-00000-of-00001 ADDED
Binary file (15.4 kB). View file
 
cnn_model.index ADDED
Binary file (557 Bytes). View file
 
cnn_model.meta ADDED
Binary file (50.2 kB). View file
 
model.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ import numpy as np
3
+ from PIL import Image
4
+ import os
5
+ # from matplotlib import image as mpimg
6
+ # from matplotlib import pyplot as plt
7
+
8
+ class api():
9
+
10
+ height=64
11
+ width=64
12
+ channels=3
13
+ model_name = 'cnn_model'
14
+ classes = { 0 : 'Zero' , 1 : 'One' , 2 : 'Two' , 3 : 'Three' , 4 : 'Four' , 5 : 'Five' }
15
+
16
+ def reset_graph(self,seed=42):
17
+ tf.reset_default_graph()
18
+ tf.set_random_seed(seed)
19
+ np.random.seed(seed)
20
+
21
+
22
+ def __init__(self,upload_path='uploads'):
23
+
24
+ self.upload_path = upload_path
25
+
26
+ # self.model_name = 'cnn_model'
27
+ print('print',os.path.join('signs_api','{}.meta'.format(self.model_name)))
28
+
29
+ # self.import_meta = tf.train.import_meta_graph(os.path.join('signs_api','{}.meta'.format(self.model_name)))
30
+
31
+ def predict(self,im):
32
+
33
+ try :
34
+
35
+ # im = Image.open( os.path.join(self.upload_path,filename) )
36
+
37
+ #image size
38
+ size=(self.height,self.width)
39
+ #resize image
40
+ out = im.resize(size)
41
+
42
+ test_image = np.array(out.getdata())
43
+
44
+ test_image = test_image.reshape((-1,self.height,self.width,self.channels))
45
+
46
+ # to make this notebook's output stable across runs
47
+ self.reset_graph()
48
+
49
+ # import meta from directory
50
+ # import_meta = tf.train.import_meta_graph('{}.meta'.format(self.model_name))
51
+ import_meta = tf.train.import_meta_graph(os.path.join('signs_api','{}.meta'.format(self.model_name)))
52
+
53
+ with tf.Session() as sess:
54
+
55
+ # tf.train.latest_checkpoint(<dir>) also works
56
+
57
+ import_meta.restore(sess,'{}.ckpt'.format( os.path.join('signs_api',self.model_name) ) )
58
+
59
+ # W1_val = sess.graph.get_tensor_by_name('W1:0')
60
+
61
+ # X_val = sess.graph.get_tensor_by_name('Placeholder:0')
62
+
63
+ ArgMax = sess.graph.get_tensor_by_name('ArgMax:0')
64
+
65
+ ArgMax_val = ArgMax.eval({ 'Placeholder:0' : test_image })
66
+
67
+ # graph = tf.get_default_graph()
68
+
69
+ # for op in graph.get_operations():
70
+ # print(op.name)
71
+
72
+ # print('W1_val',W1_val)
73
+ # print('X_val',X_val)
74
+ print('ArgMax',ArgMax_val)
75
+ index = ArgMax_val.tolist()[0]
76
+ class_val = self.classes[index]
77
+
78
+ # os.remove(os.path.join(self.upload_path,filename))
79
+
80
+ return { 'value' : index , 'class' : class_val }
81
+
82
+ except (OSError,IOError) as e:
83
+ print('error',e)
84
+ return { 'error' : True }
requriements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ tensorflow==1.15.0
2
+ numpy
3
+ Pillow