keras_model_to_pmml module

Classes used in keras_model_to_pmml.py

class keras_model_to_pmml.KerasDataDictionary(dataSet, predictedClasses)[source]

Bases: PMML43Ext.DataDictionary

KerasDataDictionary stores the class information to be predicted in the PMML model. The current implementation takes care of the Imagenet 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.
Returns:

Return type:

Nyoka’s Dictionary Object

class keras_model_to_pmml.KerasHeader(description, copyright)[source]

Bases: PMML43Ext.Header

Creates header for Keras PMML model file using Nyoka

Parameters:
  • copyright (String) – Adds the information about the copyright.
  • description (String) – Description of the PMML file provided as a default
  • Timestamp (Datetime) – Timestamp of the time when the file is created
Returns:

Return type:

Nyoka header object

class keras_model_to_pmml.KerasLocalTransformations(model_name)[source]

Bases: PMML43Ext.LocalTransformations

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

Parameters:model_name (String) – Name of the model (internally used to be specific for Keras)
Returns:
Return type:Nyoka’s Transformations Object
class keras_model_to_pmml.KerasMiningSchema(dataSet=None)[source]

Bases: PMML43Ext.MiningSchema

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

Parameters:dataSet (String) – Name of the dataset
Returns:
Return type:Nyoka’s Mining Schema Object
class keras_model_to_pmml.KerasNetwork(keras_model, model_name, dataSet=None, predictedClasses=None)[source]

Bases: PMML43Ext.DeepNetwork

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

Parameters:
  • model_name (String) – Name of the model
  • functionName (String) – Regression or Classification, currently supports classification functionName
  • numberOfLayers (Int) – Number of layers in the architecture
  • isScorable (Boolean) – True or False
  • Extension (Nyoka's extention tag) – Allows to pass extra information in Nyoka objects
  • MiningSchema (Nyoka's Mining schema object) – Nyoka’s miningschema object to be passed
  • Output (Nyoka's Output object) – Nyoka’s Output object to be passed
  • LocalTransformations (Nyoka's LocalTransformations object) – Nyoka’s LocalTransformations object to be passed
  • NetworkLayer (Nyoka's LocalTransformations object) – Nyoka’s NetworkLayer object to be passed
Returns:

Return type:

Nyoka’s DeepNetwork Object

class keras_model_to_pmml.KerasNetworkLayer(layer, layer_type)[source]

Bases: PMML43Ext.NetworkLayer

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

Parameters:
  • inputFieldName (String) – This parameter is required only for Input layer in keras
  • layerType (String) – Any Keras layer (e.g. Input, Dense, Conv2D)
  • connectionLayerId (String) – Name of the previous layer ID
  • layerId (String) – Layer ID for defined layer
  • normalizationMethod (String) – Name of normalization method here
  • LayerParameters (Nyoka LayerParamter Object) – Nyoka’s LayerParameter object which has information of Layerparamters (eg, input dimension and output dimension).
  • LayerWeights (Nyoka's LayerWeights object) – LayerWeights goes inside the LayerParameters object and provide information about the weigth matrix of the layer.
  • LayerBias (Nyoka's LayerBias object) – LayerBias goes inside the LayerParameters object and provide value of the bias matrix.
Returns:

Return type:

Nyoka NetworkLayer object

class keras_model_to_pmml.KerasOutput(predictedClasses=None)[source]

Bases: PMML43Ext.Output

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

Parameters:predictedClasses (List) – List of Classes for which model has been trained
Returns:
Return type:Nyoka’s Output Object
class keras_model_to_pmml.KerasToPmml(keras_model, model_name='KerasNet', description='Keras Models in PMML', copyright='Internal User', dataSet=None, predictedClasses=None)[source]

Bases: PMML43Ext.PMML

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

Parameters:
  • keras_model (keras model object) – Keras model object
  • model_name (String) – Name to be given to the model in PMML.
  • dataSet (String (Optional)) – Name of the dataset
  • predictedClasses (List) – List of the class names for which model has been trained
Returns:

Return type:

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