代码拉取完成,页面将自动刷新
import numpy as np
import tensorflow as tf
from flask import Flask, jsonify, render_template, request
from mnist import model
x = tf.placeholder("float", [None, 784])
sess = tf.Session()
# restore trained data
with tf.variable_scope("regressions"):
y1, variables = model.regressions(x)
saver = tf.train.Saver(variables)
saver.restore(sess, "mnist/data/regressions.ckpt")
with tf.variable_scope("convolutional"):
keep_prob = tf.placeholder("float")
y2, variables = model.convolutional(x, keep_prob)
saver = tf.train.Saver(variables)
saver.restore(sess, "mnist/data/convolutional.ckpt")
def regressions(input):
return sess.run(y1, feed_dict={x: input}).flatten().tolist()
def convolutional(input):
return sess.run(y2, feed_dict={x: input, keep_prob: 1.0}).flatten().tolist()
# webapp
app = Flask(__name__)
@app.route('/api/mnist', methods=['post'])
def mnist():
input = ((255 - np.array(request.json, dtype=np.uint8)) / 255.0).reshape(1, 784)
output1 = regressions(input)
output2 = convolutional(input)
return jsonify(results=[output1, output2])
@app.route('/')
def main():
return render_template('index.html')
if __name__ == '__main__':
app.debug=True
app.run(host='127.0.0.1',port=8000)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。