DEEPaaS API

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.

Integrate your model with the API

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 API methods. 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.

Here is example of the implementation of the methods

  1. Define the entrypoints to your model

You must define the entrypoints to this file in the setup.cfg as following:

[entry_points]
deepaas.model =
    pkg_name = pkg_name.api

Here is an example of the entrypoint definition in the setup.cfg file.

Tip

When developing a model with the DEEP DS template, the entrypoints and the Python file for the API methods will automatically be created at pkg_name/models/model.py.

Methods

get_metadata()

Return metadata from the exposed model.

Returns:dictionary containing the model’s metadata. Possible keys of this dict can include: ‘Name’, ‘Version’, ‘Summary’, ‘Home-page’, ‘Author’, ‘Author-email’, ‘License’, etc.
get_train_args(*args)

Function to expose to the API what are the typical parameters needed to run the training.

Returns:a dict of dicts with the following structure to feed the DEEPaaS API parser:
{ 'arg1' : {'default': '1',     #value must be a string (use json.dumps to convert Python objects)
            'help': '',         #can be an empty string
            'required': False   #bool
            },
  'arg2' : {...
            },
...
}
train(user_conf)

Function to train your model.

Parameters:user_conf (dict) – User configuration to train a model with custom parameters. It has the same keys as the dict returned by get_train_args(). The values of this dict can be loaded back as Python objects using json.loads. An example of a possible user_conf could be:
{'num_classes': 'null',
 'lr_step_decay': '0.1',
 'lr_step_schedule': '[0.7, 0.9]',
 'use_early_stopping': 'false'}
predict_file(path, **kwargs)

Perform a prediction from a file in the local filesystem.

Parameters:path (str) – Path to the file
Returns:dictionary of predictions
Return type:dict
predict_data(data, **kwargs)

Perform a prediction from the data passed in the arguments. This method will use the raw data that is passed in the data argument to perfom the prediction.

Parameters:data – raw data to be analized
predict_url(url, *args)

Perform a prediction from a remote URL. This method will perform a prediction based on the data stored in the URL passed as argument.

Parameters:url (str) – URL pointing to the data to be analized