https://www.tensorflow.org/tfx/serving/api_rest
tensorflow/serving#1317
https://towardsdatascience.com/image-classification-on-tensorflow-serving-with-grpc-or-rest-call-for-inference-fd3216ebd4f3
Last active
September 9, 2020 10:37
-
-
Save nwatab/7ddc9742f63e4c2be1a9a0b9fd9ed2f1 to your computer and use it in GitHub Desktop.
Flask API requests tensorflow serving minimum example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
from flask import Flask, request, jsonify | |
import requests | |
app = Flask(__name__) | |
@app.route('/predict', methods=['POST']) | |
def predict(): | |
if request.method == 'POST': | |
headers = {"content-type": "application/json"} | |
data = { | |
'instances': np.random.rand(8, 224, 224, 3).tolist() | |
} | |
data = json.dumps(data) | |
predictions = requests.post('http://localhost:8501/v1/models/yourmodel:predict', data=data, headers=headers) | |
return jsonify(predictions) | |
if __name__ == '__main__': | |
app.run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker pull tensorflow/serving | |
docker run -p 8500:8500 -p 8501:8501 \ | |
--mount type=bind,source=/abusolute/path/to/saved_model/,target=/models/yourmodel \ | |
-e MODEL_NAME=yourmodel -t tensorflow/serving |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment