Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TMVA::Experimental::SOFIE::PyKeras::INTERNAL Namespace Reference

Typedefs

using KerasMethodMap = std::unordered_map< std::string, std::unique_ptr< ROperator >(*)(PyObject *fLayer)>
 
using KerasMethodMapWithActivation = std::unordered_map< std::string, std::unique_ptr< ROperator >(*)(PyObject *fLayer)>
 

Functions

void AddKerasLayer (RModel &rmodel, PyObject *fLayer)
 Adds equivalent ROperator with respect to Keras model layer into the referenced RModel object.
 
std::unique_ptr< ROperatorMakeKerasActivation (PyObject *fLayer)
 Prepares a ROperator object for Keras activation layer.
 
std::unique_ptr< ROperatorMakeKerasBatchNorm (PyObject *fLayer)
 Prepares a ROperator object for Keras BatchNorm layer.
 
std::unique_ptr< ROperatorMakeKerasBinary (PyObject *fLayer)
 Prepares a ROperator object for Keras binary operations like Add, subtract, and multiply.
 
std::unique_ptr< ROperatorMakeKerasConcat (PyObject *fLayer)
 Prepares a ROperator object for Keras Concat layer.
 
std::unique_ptr< ROperatorMakeKerasConv (PyObject *fLayer)
 Prepares a ROperator object for Keras Conv Layer.
 
std::unique_ptr< ROperatorMakeKerasDense (PyObject *fLayer)
 Prepares a ROperator object for Keras Dense Layer.
 
std::unique_ptr< ROperatorMakeKerasIdentity (PyObject *fLayer)
 Prepares a ROperator object for Keras Identity and Dropout Layer.
 
std::unique_ptr< ROperatorMakeKerasLeakyRelu (PyObject *fLayer)
 Prepares a ROperator object for Keras Leaky Relu activation.
 
std::unique_ptr< ROperatorMakeKerasPermute (PyObject *fLayer)
 Prepares a ROperator object for Keras Permute layer.
 
std::unique_ptr< ROperatorMakeKerasReLU (PyObject *fLayer)
 Prepares a ROperator object for Keras ReLU activation.
 
std::unique_ptr< ROperatorMakeKerasReshape (PyObject *fLayer)
 Prepares a ROperator object for Keras Reshape layer.
 
std::unique_ptr< ROperatorMakeKerasSelu (PyObject *fLayer)
 Prepares a ROperator object for Keras Selu activation.
 
std::unique_ptr< ROperatorMakeKerasSigmoid (PyObject *fLayer)
 Prepares a ROperator object for Keras Sigmoid activation.
 
std::unique_ptr< ROperatorMakeKerasSoftmax (PyObject *fLayer)
 Prepares a ROperator object for Keras Softmax activation.
 
std::unique_ptr< ROperatorMakeKerasSwish (PyObject *fLayer)
 Prepares a ROperator object for Keras Swish activation.
 
std::unique_ptr< ROperatorMakeKerasTanh (PyObject *fLayer)
 Prepares a ROperator object for Keras Tanh activation.
 

Variables

const KerasMethodMap mapKerasLayer
 
const KerasMethodMapWithActivation mapKerasLayerWithActivation
 

Typedef Documentation

◆ KerasMethodMap

using TMVA::Experimental::SOFIE::PyKeras::INTERNAL::KerasMethodMap = typedef std::unordered_map<std::string, std::unique_ptr<ROperator> (*)(PyObject *fLayer)>

Definition at line 66 of file RModelParser_Keras.cxx.

◆ KerasMethodMapWithActivation

using TMVA::Experimental::SOFIE::PyKeras::INTERNAL::KerasMethodMapWithActivation = typedef std::unordered_map<std::string, std::unique_ptr<ROperator> (*)(PyObject *fLayer)>

Definition at line 67 of file RModelParser_Keras.cxx.

Function Documentation

◆ AddKerasLayer()

void TMVA::Experimental::SOFIE::PyKeras::INTERNAL::AddKerasLayer ( RModel rmodel,
PyObject fLayer 
)

Adds equivalent ROperator with respect to Keras model layer into the referenced RModel object.

Parameters
[in]rmodelRModel object
[in]fLayerPython Keras layer as a Dictionary object
[out]RModelobject with the added ROperator

Function adds equivalent ROperator into the referenced RModel object. Keras models can have layers like Dense and Conv which have activation function as an attribute. Function first searches if layer object is among the ones which don't have activation attribute and then calls the respective preparation function to get the ROperator object, which is then added into the RModel object. If passed layer is among the ones which may have activation attribute, then it checks for the activation attribute, if present then first adds the primary operator into the RModel object, and then adds the operator for the activation function with appropriate changes in the names of input and output tensors for both of them. Example of such layers is the Dense Layer. For a dense layer with input tensor name dense2BiasAdd0 and output tensor name dense3Relu0 with relu as activation attribute will be transformed into a ROperator_Gemm with input tensor name dense2BiasAdd0 & output tensor name dense3Dense (layerName+layerType), and a subsequent ROperator_Relu with input tensor name as dense3Dense and output tensor name as dense3Relu0.

For developing new preparatory functions for supporting Keras layers in future, all one needs is to extract the required properties and attributes from the fLayer dictionary which contains all the information about any Keras layer and after any required transformations, these are passed for instantiating the ROperator object.

The fLayer dictionary which holds all the information about a Keras layer has following structure:-

dict fLayer { 'layerType'       : Type of the Keras layer
              'layerAttributes' : Attributes of the keras layer as returned by layer.get_config()
              'layerInput'      : List of names of input tensors
              'layerOutput'     : List of names of output tensors
              'layerDType'      : Data-type of the Keras layer
              'layerWeight'     : List of weight tensor names of Keras layers
            } 

Definition at line 142 of file RModelParser_Keras.cxx.

◆ MakeKerasActivation()

std::unique_ptr< ROperator > TMVA::Experimental::SOFIE::PyKeras::INTERNAL::MakeKerasActivation ( PyObject fLayer)

Prepares a ROperator object for Keras activation layer.

Parameters
[in]fLayerPython Keras layer as a Dictionary object
Returns
Unique pointer to ROperator object

For Keras's keras.layers.Activation layer, the activation attribute is extracted and appropriate function for adding the function is called.

Definition at line 363 of file RModelParser_Keras.cxx.

◆ MakeKerasBatchNorm()

std::unique_ptr< ROperator > TMVA::Experimental::SOFIE::PyKeras::INTERNAL::MakeKerasBatchNorm ( PyObject fLayer)

Prepares a ROperator object for Keras BatchNorm layer.

Parameters
[in]fLayerPython Keras layer as a Dictionary object
Returns
Unique pointer to ROperator object

Definition at line 623 of file RModelParser_Keras.cxx.

◆ MakeKerasBinary()

std::unique_ptr< ROperator > TMVA::Experimental::SOFIE::PyKeras::INTERNAL::MakeKerasBinary ( PyObject fLayer)

Prepares a ROperator object for Keras binary operations like Add, subtract, and multiply.

Parameters
[in]fLayerPython Keras layer as a Dictionary object
Returns
Unique pointer to ROperator object

For instantiating a ROperator_BasicBinary object, the names of input & output tensors, the data-type of the layer and the operation type are extracted.

Definition at line 706 of file RModelParser_Keras.cxx.

◆ MakeKerasConcat()

std::unique_ptr< ROperator > TMVA::Experimental::SOFIE::PyKeras::INTERNAL::MakeKerasConcat ( PyObject fLayer)

Prepares a ROperator object for Keras Concat layer.

Parameters
[in]fLayerPython Keras layer as a Dictionary object
Returns
Unique pointer to ROperator object

Definition at line 678 of file RModelParser_Keras.cxx.

◆ MakeKerasConv()

std::unique_ptr< ROperator > TMVA::Experimental::SOFIE::PyKeras::INTERNAL::MakeKerasConv ( PyObject fLayer)

Prepares a ROperator object for Keras Conv Layer.

Parameters
[in]fLayerPython Keras layer as a Dictionary object
Returns
Unique pointer to ROperator object

For Keras's Conv layer, the names of the input tensor, output tensor, and weight tensors are extracted, along with attributes like dilation_rate, groups, kernel size, padding, strides. Padding attribute is then computed for ROperator depending on Keras' attribute parameter.

Definition at line 282 of file RModelParser_Keras.cxx.

◆ MakeKerasDense()

std::unique_ptr< ROperator > TMVA::Experimental::SOFIE::PyKeras::INTERNAL::MakeKerasDense ( PyObject fLayer)

Prepares a ROperator object for Keras Dense Layer.

Parameters
[in]fLayerPython Keras layer as a Dictionary object
Returns
Unique pointer to ROperator object

For Keras's Dense layer, the names of the input tensor, output tensor, and weight tensors are extracted, and then are passed to instantiate a ROperator_Gemm object using the required attributes.

Definition at line 237 of file RModelParser_Keras.cxx.

◆ MakeKerasIdentity()

std::unique_ptr< ROperator > TMVA::Experimental::SOFIE::PyKeras::INTERNAL::MakeKerasIdentity ( PyObject fLayer)

Prepares a ROperator object for Keras Identity and Dropout Layer.

Parameters
[in]fLayerPython Keras layer as a Dictionary object
Returns
Unique pointer to ROperator object

Dropout will have no effect in inference, so instead an Identity operator is added to mimic its presence in the Keras model

Definition at line 741 of file RModelParser_Keras.cxx.

◆ MakeKerasLeakyRelu()

std::unique_ptr< ROperator > TMVA::Experimental::SOFIE::PyKeras::INTERNAL::MakeKerasLeakyRelu ( PyObject fLayer)

Prepares a ROperator object for Keras Leaky Relu activation.

Parameters
[in]fLayerPython Keras layer as a Dictionary object
Returns
Unique pointer to ROperator object

For instantiating a ROperator_LeakyRelu object, the names of input & output tensors, the data-type and the alpha attribute of the layer are extracted.

Definition at line 496 of file RModelParser_Keras.cxx.

◆ MakeKerasPermute()

std::unique_ptr< ROperator > TMVA::Experimental::SOFIE::PyKeras::INTERNAL::MakeKerasPermute ( PyObject fLayer)

Prepares a ROperator object for Keras Permute layer.

Parameters
[in]fLayerPython Keras layer as a Dictionary object
Returns
Unique pointer to ROperator object

The Permute layer in Keras has an equivalent Tranpose operator in ONNX. For adding a Transpose operator, the permute dimensions are found, if they exist are passed in instantiating the ROperator, else default values are used.

Definition at line 579 of file RModelParser_Keras.cxx.

◆ MakeKerasReLU()

std::unique_ptr< ROperator > TMVA::Experimental::SOFIE::PyKeras::INTERNAL::MakeKerasReLU ( PyObject fLayer)

Prepares a ROperator object for Keras ReLU activation.

Parameters
[in]fLayerPython Keras layer as a Dictionary object
Returns
Unique pointer to ROperator object

For instantiating a ROperator_Relu object, the names of input & output tensors and the data-type of the layer are extracted.

Definition at line 384 of file RModelParser_Keras.cxx.

◆ MakeKerasReshape()

std::unique_ptr< ROperator > TMVA::Experimental::SOFIE::PyKeras::INTERNAL::MakeKerasReshape ( PyObject fLayer)

Prepares a ROperator object for Keras Reshape layer.

Parameters
[in]fLayerPython Keras layer as a Dictionary object
Returns
Unique pointer to ROperator object

Definition at line 654 of file RModelParser_Keras.cxx.

◆ MakeKerasSelu()

std::unique_ptr< ROperator > TMVA::Experimental::SOFIE::PyKeras::INTERNAL::MakeKerasSelu ( PyObject fLayer)

Prepares a ROperator object for Keras Selu activation.

Parameters
[in]fLayerPython Keras layer as a Dictionary object
Returns
Unique pointer to ROperator object

For instantiating a ROperator_Selu object, the names of input & output tensors and the data-type of the layer are extracted.

Definition at line 413 of file RModelParser_Keras.cxx.

◆ MakeKerasSigmoid()

std::unique_ptr< ROperator > TMVA::Experimental::SOFIE::PyKeras::INTERNAL::MakeKerasSigmoid ( PyObject fLayer)

Prepares a ROperator object for Keras Sigmoid activation.

Parameters
[in]fLayerPython Keras layer as a Dictionary object
Returns
Unique pointer to ROperator object

For instantiating a ROperator_Sigmoid object, the names of input & output tensors and the data-type of the layer are extracted.

Definition at line 441 of file RModelParser_Keras.cxx.

◆ MakeKerasSoftmax()

std::unique_ptr< ROperator > TMVA::Experimental::SOFIE::PyKeras::INTERNAL::MakeKerasSoftmax ( PyObject fLayer)

Prepares a ROperator object for Keras Softmax activation.

Parameters
[in]fLayerPython Keras layer as a Dictionary object
Returns
Unique pointer to ROperator object

For instantiating a ROperator_Softmax object, the names of input & output tensors and the data-type of the layer are extracted.

Definition at line 468 of file RModelParser_Keras.cxx.

◆ MakeKerasSwish()

std::unique_ptr< ROperator > TMVA::Experimental::SOFIE::PyKeras::INTERNAL::MakeKerasSwish ( PyObject fLayer)

Prepares a ROperator object for Keras Swish activation.

Parameters
[in]fLayerPython Keras layer as a Dictionary object
Returns
Unique pointer to ROperator object

For instantiating a ROperator_Swish object, the names of input & output tensors and the data-type of the layer are extracted.

Definition at line 551 of file RModelParser_Keras.cxx.

◆ MakeKerasTanh()

std::unique_ptr< ROperator > TMVA::Experimental::SOFIE::PyKeras::INTERNAL::MakeKerasTanh ( PyObject fLayer)

Prepares a ROperator object for Keras Tanh activation.

Parameters
[in]fLayerPython Keras layer as a Dictionary object
Returns
Unique pointer to ROperator object

For instantiating a ROperator_Tanh object, the names of input & output tensors and the data-type of the layer are extracted.

Definition at line 524 of file RModelParser_Keras.cxx.

Variable Documentation

◆ mapKerasLayer

const KerasMethodMap TMVA::Experimental::SOFIE::PyKeras::INTERNAL::mapKerasLayer
Initial value:
= {
{"Activation", &MakeKerasActivation},
{"Permute", &MakeKerasPermute},
{"BatchNormalization", &MakeKerasBatchNorm},
{"Reshape", &MakeKerasReshape},
{"Concatenate", &MakeKerasConcat},
{"swish", &MakeKerasSwish},
{"Add", &MakeKerasBinary},
{"Subtract", &MakeKerasBinary},
{"Multiply", &MakeKerasBinary},
{"Softmax", &MakeKerasSoftmax},
{"tanh", &MakeKerasTanh},
{"LeakyReLU", &MakeKerasLeakyRelu},
{"Identity", &MakeKerasIdentity},
{"Dropout", &MakeKerasIdentity},
{"ReLU", &MakeKerasReLU},
{"relu", &MakeKerasReLU},
{"selu", &MakeKerasSelu},
{"sigmoid", &MakeKerasSigmoid},
{"softmax", &MakeKerasSoftmax}
}
std::unique_ptr< ROperator > MakeKerasPermute(PyObject *fLayer)
Prepares a ROperator object for Keras Permute layer.
std::unique_ptr< ROperator > MakeKerasLeakyRelu(PyObject *fLayer)
Prepares a ROperator object for Keras Leaky Relu activation.
std::unique_ptr< ROperator > MakeKerasBinary(PyObject *fLayer)
Prepares a ROperator object for Keras binary operations like Add, subtract, and multiply.
std::unique_ptr< ROperator > MakeKerasTanh(PyObject *fLayer)
Prepares a ROperator object for Keras Tanh activation.
std::unique_ptr< ROperator > MakeKerasSoftmax(PyObject *fLayer)
Prepares a ROperator object for Keras Softmax activation.
std::unique_ptr< ROperator > MakeKerasReLU(PyObject *fLayer)
Prepares a ROperator object for Keras ReLU activation.
std::unique_ptr< ROperator > MakeKerasIdentity(PyObject *fLayer)
Prepares a ROperator object for Keras Identity and Dropout Layer.
std::unique_ptr< ROperator > MakeKerasSigmoid(PyObject *fLayer)
Prepares a ROperator object for Keras Sigmoid activation.
std::unique_ptr< ROperator > MakeKerasSelu(PyObject *fLayer)
Prepares a ROperator object for Keras Selu activation.
std::unique_ptr< ROperator > MakeKerasActivation(PyObject *fLayer)
Prepares a ROperator object for Keras activation layer.

Definition at line 69 of file RModelParser_Keras.cxx.

◆ mapKerasLayerWithActivation

const KerasMethodMapWithActivation TMVA::Experimental::SOFIE::PyKeras::INTERNAL::mapKerasLayerWithActivation
Initial value:
= {
{"Dense", &MakeKerasDense},
{"Conv2D", &MakeKerasConv},
}
std::unique_ptr< ROperator > MakeKerasConv(PyObject *fLayer)
Prepares a ROperator object for Keras Conv Layer.
std::unique_ptr< ROperator > MakeKerasDense(PyObject *fLayer)
Prepares a ROperator object for Keras Dense Layer.

Definition at line 95 of file RModelParser_Keras.cxx.