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

Namespaces

namespace  INTERNAL
 

Functions

RModel Parse (std::string filename, int batch_size=-1)
 Parser function for translatng Keras .h5 model into a RModel object.
 

Variables

static PyObject *(&) GetValueFromDict (PyObject *, const char *) = PyMethodBase::GetValueFromDict
 
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,
int  batch_size = -1 
)

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. One can specify as option a batch size that can be used when the input Keras model has not a defined input batch size : e.g. for input = (input_dim,)

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().

Provide optionally a batch size that can be used to overwrite the one given by the model. If a batch size is not given 1 is used if the model does not provide a batch size

Example Usage:

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

Definition at line 802 of file RModelParser_Keras.cxx.

Variable Documentation

◆ GetValueFromDict

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

Definition at line 37 of file RModelParser_Keras.cxx.

◆ PyRunString

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

Definition at line 34 of file RModelParser_Keras.cxx.

◆ PyStringAsString

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

Definition at line 35 of file RModelParser_Keras.cxx.