/
app.py
33 lines (27 loc) · 794 Bytes
/
app.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
from flask import Flask, request, jsonify
import numpy as np
from tensorflow import keras
app = Flask(__name__)
id2class = {0: "T-shirt/top",
1: "Trouser",
2: "Pullover",
3: "Dress",
4: "Coat",
5: "Sandal",
6: "Shirt",
7: "Sneaker",
8: "Bag",
9: "Ankle boot",}
model = keras.models.load_model("fashion_mnist")
@app.route('/predict', methods=['POST'])
def predict():
parameters = request.get_json(force=True)
im = np.array(parameters['image'])
im = im.astype("float32") / 255
im = np.expand_dims(im, -1)[None]
out = id2class[np.argmax(model.predict(im))]
#print(im.shape)
#print(out)
return out
if __name__ == '__main__':
app.run(host='0.0.0.0')