Logo ROOT  
Reference Guide
TMVA::Experimental::SOFIE::PyKeras Namespace Reference


namespace  INTERNAL


RModel Parse (std::string filename)
 Parser function for translatng Keras .h5 model into a RModel object. More...


static void(&) PyRunString (TString, PyObject *, PyObject *) = PyMethodBase::PyRunString
static const char *(&) PyStringAsString (PyObject *) = PyMethodBase::PyStringAsString

Function Documentation

◆ Parse()

RModel TMVA::Experimental::SOFIE::PyKeras::Parse ( std::string  filename)

Parser function for translatng Keras .h5 model into a RModel object.

Accepts the file location of a Keras model and returns the equivalent RModel object.

[in]filenamefile location of Keras .h5
Parsed RModel object

The Parse() function defined in TMVA::Experimental::SOFIE::PyKeras will parse a trained Keras .h5 model into a RModel Object. After loading the model in a Python Session, the included layers are extracted with properties like Layer type, Attributes, Input tensor names, Output tensor names, data-type and names of the weight/initialized tensors. The extracted layers from the model are then passed into AddKerasLayer() which prepares the specific ROperator and adds them into the RModel object. The layers are also checked for adding any required routines for executing the generated Inference code.

For adding the Initialized tensors into the RModel object, the weights are extracted from the Keras model in the form of NumPy arrays, which are then passed into AddInitializedTensor() after appropriate casting.

Input tensor infos are required to be added which will contain their names, shapes and data-types. For keras models with single input tensors, the tensor shape is returned as a Tuple object, whereas for multi-input models, the tensor shape is returned as a List of Tuple object containing the shape of the individual input tensors. SOFIE's RModel also requires that the Keras models are initialized with Batch Size. The GetDataFromTuple() are called on the Tuple objects, which then returns the shape vector required to call the AddInputTensorInfo().

For adding the Output Tensor infos, only the names of the model's output tensors are extracted and are then passed into AddOutputTensorNameList().

Example Usage:

RModel model = PyKeras::Parse("trained_model_dense.h5");
RModel Parse(std::string filename)
Parser function for translatng Keras .h5 model into a RModel object.

Definition at line 739 of file RModelParser_Keras.cxx.

Variable Documentation

◆ PyRunString

void(&) TMVA::Experimental::SOFIE::PyKeras::PyRunString(TString, PyObject *, PyObject *) ( TString  ,
PyObject ,
) = PyMethodBase::PyRunString

Definition at line 34 of file RModelParser_Keras.cxx.

◆ PyStringAsString

const char *(&) TMVA::Experimental::SOFIE::PyKeras::PyStringAsString(PyObject *) ( PyObject ) = PyMethodBase::PyStringAsString

Definition at line 35 of file RModelParser_Keras.cxx.