I created a Dockerfile
for tensorflow-serving
as follows:
FROM tensorflow/serving
COPY /model_dir /models/model/
and I docker-compose
it this way
tensorflow-servings:
container_name: tfserving_classifier
build: ./some_model_dir
ports:
- 8501:8501
In the tensorflow-container, the model is located in /models/model/1
Here is how I tried to serve it
# server URL
url = 'http://localhost:8501/v1/models/model/1:predict'
def make_prediction(instances):
data = json.dumps({"signature_name": "serving_default", "instances": instances.tolist()})
headers = {"content-type": "application/json"}
json_response = requests.post(url, data=data, headers=headers)
predictions = json.loads(json_response.text)['predictions']
return predictions
Here is the python code container message:
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8501): Max retries exceeded with url: /v1/models/model/1:predict (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f315c19c4c0>: Failed to establish a new connection: [Errno 111] Connection refused'))
I believe this is due to incorrect URL, how can I get the correct URL for my tensorflow-serving?
Here is the tensorflow-serving container message:
I tensorflow_serving/model_servers/server.cc:393] Running gRPC ModelServer at 0.0.0.0:8500 ...
I tensorflow_serving/model_servers/server.cc:414] Exporting HTTP/REST API at:localhost:8501 ...
CodePudding user response:
localhost
only reaches inside the container, use service name or container name of tensorflow to reach it from the script container
http://tensorflow-servings:8501/v1/models/model/1:predict