Namespaces | |
namespace | INTERNAL |
Functions | |
RModel | Parse (std::string filename) |
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 |
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] | filename | file location of Keras .h5 |
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:
Definition at line 799 of file RModelParser_Keras.cxx.
|
static |
Definition at line 37 of file RModelParser_Keras.cxx.
|
static |
Definition at line 34 of file RModelParser_Keras.cxx.
|
static |
Definition at line 35 of file RModelParser_Keras.cxx.