Using TensorFlow Serving

Having converted the front end to React the next step is to get a model making predictions from the server. TensorFlow Serving seems like the best way to do this.

Instructions are here for using Serving with Docker which is the recommended approach. 

Some tips on docker:

After you have run docker pull to get the TensorFlow Serving container you will want to list your containers:

docker ps

To run a container use docker run as per the instructions. 

docker run -p 8501:8501 --mount type=bind,source=$(pwd)/data/model/pos_checkpoint,target=/models/pos_checkpoint -e MODEL_NAME=pos_checkpoint -t tensorflow/serving

Then use docker stop XX where XX is enough of the tag from docker ps to identify that container. 

You will need to put your SavedModel into an integer folder for the version. 

The command to run a prediction using the REST endpoint is:

curl -d '{"instances":[1,2,3]}' -X POST http://localhost:8501/v1/models/pos_checkpoint:predict

That will error because the dummy tensor will fail on the python side, but now you can go ahead and get some proper data from a book as below.

With that done your model will serve on a rest endpoint. I tried it out from a jupyter notebook using the requests api and it produces the same results as the loaded model in the notebook.

Comments

Popular posts from this blog

Execute Jupyter notebooks line by line in VS Code

Text Summarisation with BERT