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

Namespaces

namespace  INTERNAL
 

Functions

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

Variables

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.

Parameters
[in]filenamefile location of Keras .h5
Returns
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 405 of file RModelParser_Keras.cxx.

Variable Documentation

◆ PyRunString

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

Definition at line 33 of file RModelParser_Keras.cxx.

◆ PyStringAsString

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

Definition at line 34 of file RModelParser_Keras.cxx.