The DEEPaaS API enables a user friendly interaction with the underlying Deep Learning modules and can be used both for training models and doing inference with services.
For a detailed up-to-date documentation please refer to the official DEEPaaS documentation.
Integrate your model with the API
The best approach to integrate your code with DEEPaaS is to create an empty template using the DEEP Modules Template. Once the template is created, move your code inside your package and define the API methods that will interface with your existing code.
To make your Deep Learning model compatible with the DEEPaaS API you have to:
1. Define the API methods for your model
Create a Python file (named for example
api.py) inside your package. In this file you can define any of the
You don’t need to define all the methods, just the ones you need.
Every other method will return a
NotImplementError when queried from the API.
Enable prediction: implement
Enable training: implement
Enable model weights preloading: implement
Enable model info: implement
If you don’t feel like reading the DEEPaaS docs (which you should), here are some examples of files you can quickly drawn inspiration from:
returning a JSON response for
returning a file (eg. image, zip, etc) for
a more complex example which also includes
Try to keep you module’s code as decoupled as possible from DEEPaaS code, so that
any future changes in the API are easy to integrate.
This means that the
api.py should mostly be an interface to
your true predict function. In pseudocode:
#api.py import utils # eg. this is where your true predict function is def predict(**kwargs): args = preprocess(kwargs) # transform deepaas input to your standard input out = utils.predict(args) # make prediction resp = postprocess(out) # transform your standard output to deepaas output return resp
2. Define the entrypoints to your model
You must define the entrypoints pointing to this file in the
setup.cfg as following:
[entry_points] deepaas.v2.model = pkg_name = pkg_name.api
Here is an example of the entrypoint
definition in the
Running the API
To start the API run:
deepaas-run --listen-ip 0.0.0.0
and go to http://0.0.0.0:5000/ui. You will see a nice UI with all the methods: