Keras Exporter Module

Classes used in Keras Exporter

class KerasDataDictionary(dataSet, predictedClasses, script_args)[source]

Bases: PMML44.DataDictionary

KerasDataDictionary stores the class information to be predicted in the PMML model. The current implementation takes care of the image class label by giving dataset name as dataSet parameter.

Parameters:
  • dataSet (String) – Name of the dataset
  • predictedClasses (List) – List of class names or values to be predicted.
  • script_args (Dictionary or None) – Parameters for the script if any preprocessing script is provided
Returns:

Return type:

Nyoka’s DataDictionary Object

class KerasHeader(description, copyright)[source]

Bases: PMML44.Header

Creates header for Keras PMML model file using Nyoka

Parameters:
  • description (String) – Description of the PMML file provided as a default
  • copyright (String) – Adds the information about the copyright.
Returns:

Return type:

Nyoka header object

class KerasLocalTransformations(keras_model, dataSet, script_args)[source]

Bases: PMML44.LocalTransformations

KerasLocalTransformations provides the information about the list of transformations applied to the data.

Parameters:
  • keras_model (Keras model object) – Keras model object
  • dataSet (String) – Name of the dataset
  • script_args (Dictionary) – Parameters for the script if any preprocessing script is provided
Returns:

Return type:

Nyoka’s LocalTransformations Object

class KerasMiningSchema(dataSet, predictedClasses)[source]

Bases: PMML44.MiningSchema

KerasMiningSchema stores the attributes which are used to build the model.

Parameters:
  • dataSet (String) – Name of the dataset
  • predictedClasses (List) – List of class names or values to be predicted.
Returns:

Return type:

Nyoka’s MiningSchema Object

class KerasNetwork(keras_model, model_name, dataSet=None, predictedClasses=None, script_args=None)[source]

Bases: PMML44.DeepNetwork

KerasNetwork creates the DeepNetwork object which stores the NetworkLayer in sequence to define the architecture.

Parameters:
  • keras_model (Keras model object) – Keras model object
  • model_name (String) – Name of the model
  • dataSet (String) – Name of the dataset
  • predictedClasses (List or None) – List of class names
  • script_args (Dictionary or None) – Parameters for the script if any preprocessing script is provided
Returns:

Return type:

Nyoka’s DeepNetwork Object

class KerasNetworkLayer(layer, dataSet, layer_type, script_args, connection_layer_id=True)[source]

Bases: PMML44.NetworkLayer

Creates Networklayer of PMML which has information about the layer type, weight matrix and bias matrix and their properties.

Parameters:
  • layer (Keras layer object) – Keras layer object
  • dataSet (String) – Name of the dataset
  • layer_type (String) – Class name of the layer
  • script_args (Dictionary or None) – Parameters for the script if any preprocessing script is provided
  • connection_layer_id (boolean) – Whether to generate connection layer IDs or not
Returns:

Return type:

Nyoka NetworkLayer object

class KerasOutput(predictedClasses=None)[source]

Bases: PMML44.Output

KerasOutput provides the information about the output representation of the PMML. (e.g. Predicted classes, probabilities)

Parameters:predictedClasses (List or None) – List of Classes for which model has been trained. If not provided, considered as Regression
Returns:
Return type:Nyoka’s Output Object
class KerasToPmml(keras_model, model_name=None, description=None, copyright=None, dataSet=None, predictedClasses=None, script_args=None)[source]

Bases: PMML44.PMML

KerasToPmml exports the Keras model object into PMML file using nyoka.

Parameters:
  • keras_model (Keras model object) – Keras model object
  • model_name (String or None) – Name to be given to the model in PMML.
  • description (Sting or None) – Description to be shown in PMML
  • dataSet (String or None) – Name of the dataset. Value is ‘image’ for Image Classifier, ‘None’ or any other value is for tabular or base64 encoded data.
  • predictedClasses (List or None) – List of the class names for which model has been trained. If not provided, assumed to be regression model.
  • script_args (Dictionary or None) –

    Contains information of the script to be used to convert image data into base64 string. Required when dataSet=`image`. Required attributes -

    content : string or function
    The content of the script
    def_name : string
    name of the function to be used. Required when content is string
    return_type : string
    The return type of the function. Valid values are (‘string’, ‘double’, ‘float’,’integer’)
    encode : boolean
    The representation of the script in PMML. If True, the script will be represented as base64 encoded string, else as plain text. If not provided, default value True is considered.
Returns:

Return type:

Creates Nyoka’s PMML object, this can be saved in file using export function

content_error
def_name_error
encode_error
ret_type_error
ret_type_value_error
validate_script_args(script_args)[source]
class KerasTransformationDictionary(dataSet, script_args)[source]

Bases: PMML44.TransformationDictionary

KerasTransformationDictionary provides the information about the list of transformations functions applied to the data.

Parameters:
  • dataSet (string) – name of the input
  • script_args (Dictionary) – Parameters for the script if any preprocessing script is provided
Returns:

Return type:

Nyoka’s TransformationDictionary object