Model Image for Python
Last updated
Last updated
This doc shows how to package a model into a format-valid docker image for the PrimeHub model deployment feature.
The PrimeHub model deployment feature is based on Seldon. This doc takes from Seldon official documentations and other resources which are listed in the last part.
Docker:
Create a requirements.txt
file and write down all required packages.
Create a Dockerfile
with the following content.
Create a MyModel.py
file with the following example template.
File and class name MyModel
should be the same as MODEL_NAME in Dockerfile
Load or initiate your model under the __init__
function
The predict method takes a numpy-array X
and list of string feature_names
(optional), then returns an array of predictions (the return array should be at least 2-dimensional)
More detailed information on how to write the Python file for model deployment in different frameworks, please refer to the section .
Make sure you are in the folder that includes requirements.txt
, Dockerfile
, python file for model deployment
, and model file
.
Execute following command to install environment and package our model file into the target image my-model-image
.
Then check the image by docker images
.
In order to make sure your model image is well packaged, you can run your model as a Docker container locally.
And curl (replace ndarray
content in curl example according to your application).
You have successfully built the docker image for the PrimeHub model deployment.
Next, push the image into the docker hub (or other docker registries) and check PrimeHub tutorial to serve the model under PrimeHub.
Tag your docker image.
Then push to docker registry.
Here are some Python snippets of how to export a model file then load it and run the prediction in another file. By following the Python wrapper format, PrimeHub supports various popular ML frameworks to serve models.
Output a model file model/deep_mnist_model
MyModel.py
, load a model and run a prediction
Output a model file 1
MyModel.py
, load a model and run a prediction
Output a model file keras-mnist.h5
MyModel.py
, load a model and run a prediction
Output a model file IrisClassifier.sav
MyModel.py
, load a model and run a prediction
Output a model file mnist_cnn.pt
MyModel.py
, load a model and run a prediction
Output a model file xgboost.model
MyModel.py
, load a model and run a prediction
Output a model file mx-model___
MyModel.py
, load a model and run a prediction
Output a model file model.pkl
MyModel.py
, load a model and run a prediction