Wrapper for Cloud API Models

Provides class to wrap existing models in different frameworks so that they provide a unified API to the benchmarks.

AipModel Base class for models hosted on Baidu AIP platform.
AipAntiPornModel Create a Model instance from an AipAntiPorn model.
GoogleCloudModel Base class for models in Google Cloud.
GoogleSafeSearchModel Create a :class: Model instance from a GoogleSafeSearchModel model.
GoogleObjectDetectionModel Create a :class: Model instance from a GoogleObjectDetectionModel model.
class perceptron.models.classification.AipModel(credential, bounds=(0, 255), channel_axis=3, preprocessing=(0, 1))[source]

Base class for models hosted on Baidu AIP platform.

Parameters:
credential : tuple

Tuple of (appId, apiKey, secretKey) for using AIP API.

bounds : tuple

Tuple of lower and upper bound for the pixel values, usually (0, 1) or (0, 255).

channel_axis : int

The index of the axis that represents color channels.

preprocessing: 2-element tuple with floats or numpy arrays

Elementwises preprocessing of input; we first substract the first element of preprocessing from the input and then divide the input by the second element.

class perceptron.models.classification.AipAntiPornModel(credential, bounds=(0, 255), channel_axis=3, preprocessing=(0, 1))[source]

Create a Model instance from an AipAntiPorn model.

Parameters:
credential : tuple

Tuple of (appId, apiKey, secretKey) for using AIP API.

bounds : tuple

Tuple of lower and upper bound for the pixel values, usually (0, 1) or (0, 255).

channel_axis : int

The index of the axis that represents color channels.

preprocessing: 2-element tuple with floats or numpy arrays

Elementwises preprocessing of input; we first substract the first element of preprocessing from the input and then divide the input by the second element.

model_task(self)[source]

Get the task that the model is used for.

predictions(self, image)[source]

Get prediction for input image

Parameters:
image : numpy.ndarray

The input image in [h, n, c] ndarry format.

Returns:
list

List of anitporn prediction resutls. Each element is a dictionary containing: {‘class_name’, ‘probability’}

class perceptron.models.classification.GoogleCloudModel(bounds=(0, 255), channel_axis=3, preprocessing=(0, 1))[source]

Base class for models in Google Cloud.

Parameters:
bounds : tuple

Tuple of lower and upper bound for the pixel values, usually (0, 1) or (0, 255).

channel_axis : int

The index of the axis that represents color channels.

preprocessing: 2-element tuple with floats or numpy arrays

Elementwises preprocessing of input; we first substract the first element of preprocessing from the input and then divide the input by the second element.

Notes

To use google cloud vision models, you need to install its package pip instlal –upgrade google-cloud-vision.

class perceptron.models.classification.GoogleSafeSearchModel(bounds=(0, 255), channel_axis=3, preprocessing=(0, 1))[source]

Create a :class: Model instance from a GoogleSafeSearchModel model.

Parameters:
bounds : tuple

Tuple of lower and upper bound for the pixel values, usually (0, 1) or (0, 255).

channel_axis : int

The index of the axis that represents color channels.

preprocessing: 2-element tuple with floats or numpy arrays

Elementwises preprocessing of input; we first substract the first element of preprocessing from the input and then divide the input by the second element.

model_task(self)[source]

Get the task that the model is used for.

predictions(self, image)[source]

Get prediction for input image.

Parameters:
image : numpy.ndarray

The input image in [h, n, c] ndarry format.

Returns:
list

List of prediction resutls. Each element is a dictionary containing: {‘adult’, ‘medical’, ‘racy’, ‘spoof’, ‘violence’}.

class perceptron.models.classification.GoogleObjectDetectionModel(bounds=(0, 255), channel_axis=3, preprocessing=(0, 1))[source]

Create a :class: Model instance from a GoogleObjectDetectionModel model.

Parameters:
bounds : tuple

Tuple of lower and upper bound for the pixel values, usually (0, 1) or (0, 255).

channel_axis : int

The index of the axis that represents color channels.

preprocessing: 2-element tuple with floats or numpy arrays

Elementwises preprocessing of input; we first substract the first element of preprocessing from the input and then divide the input by the second element.

model_task(self)[source]

Get the task that the model is used for.

predictions(self, image)[source]

Get detection result for input image.

Parameters:
image : numpy.ndarray

The input image in [h, n, c] ndarry format.

Returns:
list

List of batch prediction resutls. Each element is a dictionary containing: {‘name’, ‘score’, ‘mid’, ‘bounding_poly’}.