May 2020
Intermediate to advanced
404 pages
10h 52m
English
Now, let's define the /predict route, which will be our API to respond to the predicted digit with:
@app.route('/predict/', methods=['POST'])def predict(): global model, graph imgData = request.get_data() try: stringToImage(imgData) except: f = request.files['img'] f.save('image.png') x = imread('image.png', mode='L') x = imresize(x, (28, 28)) x = x.reshape(1, 28, 28, 1) with graph.as_default(): prediction = model.predict(x) response = np.argmax(prediction, axis=1) return str(response[0])
Here, the predict() function takes in a POST method input, makes a check on the format that the file is passed in, and then saves it to the disk with the name of image.png. Then, the image is read into the program and resized to 28 x 28 ...
Read now
Unlock full access