-
Notifications
You must be signed in to change notification settings - Fork 0
/
hand_write_server.py
40 lines (29 loc) · 1.02 KB
/
hand_write_server.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
#!/usr/bin/env python3
from flask import *
from basic_framework import *
import numpy as np
app = Flask(__name__)
with tf.name_scope('normal'):
x = tf.placeholder(tf.float32, [None, 784], name='x')
with tf.name_scope('dropout'):
keep_prob = tf.placeholder(tf.float32, name='keep_prob')
tf.summary.scalar('dropout_keep_probability', keep_prob)
main_net = le_net(x, keep_prob, 'LeNet')
max_arg = tf.arg_max(main_net, 1)
sess = tf.Session()
saver_path = './checkpoints/normal/normal.ckpt'
saver = tf.train.Saver()
saver.restore(sess, saver_path)
def recognize_image(input_image):
k = sess.run(max_arg, feed_dict={x: input_image, keep_prob: 1})
return k
@app.route('/')
def index():
return render_template_string(open('hand_write.html').read())
@app.route('/recognize', methods=['POST'])
def recognize():
input_image = request.get_json()
arr = np.array(input_image)
return jsonify(recognize_image(arr.reshape([-1, 28*28])).tolist())
if __name__ == '__main__':
app.run(debug=True)