24#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION 
   25#include <numpy/arrayobject.h> 
   29namespace Experimental{
 
  173         rmodel.AddNeededStdLib(
"cmath");
 
  211            throw std::runtime_error(
"TMVA::SOFIE - Parsing Keras Activation layer " + 
fLayerActivation + 
" is not yet supported");
 
  223      throw std::runtime_error(
"TMVA::SOFIE - Parsing Keras layer " + 
fLayerType + 
" is not yet supported");
 
 
  252      std::unique_ptr<ROperator> 
op;
 
  265         throw std::runtime_error(
"TMVA::SOFIE - Unsupported - Operator Gemm does not yet support input type " + 
fLayerDType);
 
 
  305      std::vector<size_t> fAttrDilations = GetDataFromTuple(
fDilations);
 
  309      std::vector<size_t> fAttrKernelShape = GetDataFromTuple(
fKernelShape);
 
  310      std::vector<size_t> fAttrStrides     = GetDataFromTuple(fStrides);
 
  311      std::string fAttrAutopad;
 
  312      std::vector<size_t>fAttrPads;
 
  317         fAttrAutopad = 
"VALID";
 
  320         fAttrAutopad=
"NOTSET";
 
  325         long outputHeight = std::ceil(
float(inputHeight) / 
float(fAttrStrides[0]));
 
  326         long outputWidth  = std::ceil(
float(inputWidth) / 
float(fAttrStrides[1]));
 
  338         throw std::runtime_error(
"TMVA::SOFIE - RModel Keras Parser doesn't yet supports Convolution layer with padding " + 
fKerasPadding);
 
  341      std::unique_ptr<ROperator> 
op;
 
  349         throw std::runtime_error(
"TMVA::SOFIE - Unsupported - Operator Conv does not yet support input type " + 
fLayerDType);
 
 
  370         throw std::runtime_error(
"TMVA::SOFIE - Parsing Keras Activation layer " + 
fLayerActivation + 
" is not yet supported");
 
 
  393      std::unique_ptr<ROperator> 
op;
 
  399         throw std::runtime_error(
"TMVA::SOFIE - Unsupported - Operator Relu does not yet support input type " + 
fLayerDType);
 
 
  421      std::unique_ptr<ROperator> 
op;
 
  427         throw std::runtime_error(
"TMVA::SOFIE - Unsupported - Operator Selu does not yet support input type " + 
fLayerDType);
 
 
  449      std::unique_ptr<ROperator> 
op;
 
  455         throw std::runtime_error(
"TMVA::SOFIE - Unsupported - Operator Sigmoid does not yet support input type " + 
fLayerDType);
 
 
  476      std::unique_ptr<ROperator> 
op;
 
  482         throw std::runtime_error(
"TMVA::SOFIE - Unsupported - Operator Sigmoid does not yet support input type " + 
fLayerDType);
 
 
  505      std::unique_ptr<ROperator> 
op;
 
  511         throw std::runtime_error(
"TMVA::SOFIE - Unsupported - Operator Sigmoid does not yet support input type " + 
fLayerDType);
 
 
  532      std::unique_ptr<ROperator> 
op;
 
  538         throw std::runtime_error(
"TMVA::SOFIE - Unsupported - Operator Tanh does not yet support input type " + 
fLayerDType);
 
 
  559      std::unique_ptr<ROperator> 
op;
 
  565         throw std::runtime_error(
"TMVA::SOFIE - Unsupported - Operator Swish does not yet support input type " + 
fLayerDType);
 
 
  599      std::unique_ptr<ROperator> 
op;
 
  613            throw std::runtime_error(
"TMVA::SOFIE - Unsupported - Operator Transpose does not yet support input type " + 
fLayerDType);
 
 
  644      std::unique_ptr<ROperator> 
op;
 
 
  668      std::unique_ptr<ROperator> 
op;
 
 
  684      std::vector<std::string> 
inputs;
 
  691      std::unique_ptr<ROperator> 
op;
 
 
  716      std::unique_ptr<ROperator> 
op;
 
  728         throw std::runtime_error(
"TMVA::SOFIE - Unsupported - Operator Sigmoid does not yet support input type " + 
fLayerDType);
 
 
  750      std::unique_ptr<ROperator> 
op;
 
  756         throw std::runtime_error(
"TMVA::SOFIE - Unsupported - Operator Identity does not yet support input type " + 
fLayerDType);
 
 
 
  812   if (
isep != std::string::npos){
 
  817   if(!std::ifstream(
filename).good()){
 
  818        throw std::runtime_error(
"Model file "+
filename_nodir+
" not found!");
 
  822   std::time_t 
ttime = std::time(0);
 
  834       throw std::runtime_error(
"Can't init global namespace for Python");
 
  837       throw std::runtime_error(
"Can't init local namespace for Python");
 
  844   PyRunString(
"import tensorflow",fGlobalNS,fLocalNS);
 
  845   PyRunString(
"import tensorflow.keras as keras",fGlobalNS,fLocalNS);
 
  846   PyRunString(
"from tensorflow.keras.models import load_model",fGlobalNS,fLocalNS);
 
  847   PyRunString(
"print('TF/Keras Version: '+ tensorflow.__version__)",fGlobalNS,fLocalNS);
 
  850   PyRunString(
"globals().update(locals())",fGlobalNS,fLocalNS);
 
  852   PyRunString(
"for idx in range(len(model.layers)):\n" 
  853               "  layer=model.get_layer(index=idx)\n" 
  855               "  layerData['layerType']=layer.__class__.__name__\n" 
  856               "  layerData['layerAttributes']=layer.__dict__\n" 
  857               "  layerData['layerInput']=[x.name for x in layer.input] if isinstance(layer.input,list) else [layer.input.name]\n" 
  858               "  layerData['layerOutput']=[x.name for x in layer.output] if isinstance(layer.output,list) else [layer.output.name]\n" 
  859               "  layerData['layerDType']=layer.dtype\n" 
  860               "  layerData['layerWeight']=[x.name for x in layer.weights]\n" 
  861               "  modelData.append(layerData)",fGlobalNS,fLocalNS);
 
  882         rmodel.AddBlasRoutines({
"Gemm", 
"Gemv"});
 
  884         rmodel.AddBlasRoutines({
"Copy", 
"Axpy"});
 
  886         rmodel.AddBlasRoutines({
"Gemm", 
"Axpy"});
 
  896   PyRunString(
"for idx in range(len(model.get_weights())):\n" 
  898               "  weightProp['name']=model.weights[idx].name\n" 
  899               "  weightProp['dtype']=(model.get_weights())[idx].dtype.name\n" 
  900               "  weightProp['value']=(model.get_weights())[idx].transpose((3,2,0,1)).copy() if ('conv' in model.weights[idx].name and model.weights[idx].shape.ndims == 4) else (model.get_weights())[idx]\n" 
  901               "  weight.append(weightProp)",fGlobalNS,fLocalNS);
 
  945   PyRunString(
"inputNames=model.input_names",fGlobalNS,fLocalNS);
 
  946   PyRunString(
"inputShapes=model.input_shape if type(model.input_shape)==list else [model.input_shape]",fGlobalNS,fLocalNS);
 
  948   PyRunString(
"for idx in range(len(model.inputs)):\n" 
  949               "  inputTypes.append(model.inputs[idx].dtype.__str__()[9:-2])",fGlobalNS,fLocalNS);
 
  971         std::vector<size_t>fInputShape = GetDataFromTuple(
fPInputShapes);
 
  972         if (
static_cast<int>(fInputShape[0]) <= 0){
 
  974            std::cout << 
"Model has not a defined batch size ";
 
  975            if (
batch_size <=0) std::cout << 
" assume is 1 ";
 
  976            else std::cout << 
" use given value of " << 
batch_size;
 
  977            std::cout << 
" - input shape for tensor " << 
fInputName << 
" : " 
 1004         if (
static_cast<int>(fInputShape[0]) <= 0){
 
 1006            std::cout << 
"Model has not a defined batch size ";
 
 1007            if (
batch_size <=0) std::cout << 
" assume is 1 ";
 
 1008            else std::cout << 
" use given value of " << 
batch_size;
 
 1009            std::cout << 
" - input shape for tensor " 
 1028   PyRunString(
"for layerName in model.output_names:\n" 
 1029               "    outputNames.append(model.get_layer(layerName).output.name)",fGlobalNS,fLocalNS);
 
 1031   std::vector<std::string> fOutputNames;
 
 1035   rmodel.AddOutputTensorNameList(fOutputNames);
 
 
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
 
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
 
const_iterator begin() const
 
const_iterator end() const
 
static std::vector< size_t > GetDataFromTuple(PyObject *tupleObject)
Utility function which retrieves and returns the values of the Tuple object as a vector of size_t.
 
static const char * PyStringAsString(PyObject *string)
Returns const char* from Python string in PyObject.
 
static PyObject * GetValueFromDict(PyObject *dict, const char *key)
Utility function which checks if a given key is present in a Python dictionary object and returns the...
 
void PyRunString(TString code, TString errorMessage="Failed to run python code", int start=256)
Execute Python code from string.
 
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
 
std::unique_ptr< ROperator > MakeKerasConv(PyObject *fLayer)
Prepares a ROperator object for Keras Conv Layer.
 
std::unordered_map< std::string, std::unique_ptr< ROperator >(*)(PyObject *fLayer)> KerasMethodMap
 
std::unique_ptr< ROperator > MakeKerasPermute(PyObject *fLayer)
Prepares a ROperator object for Keras Permute layer.
 
std::unique_ptr< ROperator > MakeKerasBatchNorm(PyObject *fLayer)
Prepares a ROperator object for Keras BatchNorm layer.
 
std::unique_ptr< ROperator > MakeKerasSwish(PyObject *fLayer)
Prepares a ROperator object for Keras Swish activation.
 
void AddKerasLayer(RModel &rmodel, PyObject *fLayer)
Adds equivalent ROperator with respect to Keras model layer into the referenced RModel object.
 
std::unique_ptr< ROperator > MakeKerasConcat(PyObject *fLayer)
Prepares a ROperator object for Keras Concat layer.
 
std::unique_ptr< ROperator > MakeKerasLeakyRelu(PyObject *fLayer)
Prepares a ROperator object for Keras Leaky Relu activation.
 
std::unique_ptr< ROperator > MakeKerasDense(PyObject *fLayer)
Prepares a ROperator object for Keras Dense Layer.
 
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 > MakeKerasReshape(PyObject *fLayer)
Prepares a ROperator object for Keras Reshape layer.
 
std::unique_ptr< ROperator > MakeKerasReLU(PyObject *fLayer)
Prepares a ROperator object for Keras ReLU activation.
 
const KerasMethodMapWithActivation mapKerasLayerWithActivation
 
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::unordered_map< std::string, std::unique_ptr< ROperator >(*)(PyObject *fLayer)> KerasMethodMapWithActivation
 
const KerasMethodMap mapKerasLayer
 
std::unique_ptr< ROperator > MakeKerasActivation(PyObject *fLayer)
Prepares a ROperator object for Keras activation layer.
 
static void(& PyRunString)(TString, PyObject *, PyObject *)
 
RModel Parse(std::string filename, int batch_size=-1)
Parser function for translatng Keras .h5 model into a RModel object.
 
static const char *(& PyStringAsString)(PyObject *)
 
static PyObject *(& GetValueFromDict)(PyObject *, const char *)
 
std::string ConvertShapeToString(std::vector< size_t > shape)
 
std::string ConvertTypeToString(ETensorType type)
 
ETensorType ConvertStringToType(std::string type)
 
create variable transformations