Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TMVA_SOFIE_ONNX.C File Reference

Detailed Description

View in nbviewer Open in SWAN
This macro provides a simple example for the parsing of ONNX files into RModel object and further generating the .hxx header files for inference.

using namespace TMVA::Experimental;
void TMVA_SOFIE_ONNX(std::string inputFile = ""){
if (inputFile.empty() )
inputFile = std::string(gROOT->GetTutorialsDir()) + "/machine_learning/Linear_16.onnx";
//Creating parser object to parse ONNX files
SOFIE::RModel model = parser.Parse(inputFile, true);
//Generating inference code
model.Generate();
// write the code in a file (by default Linear_16.hxx and Linear_16.dat
model.OutputGenerated();
//Printing required input tensors
//Printing initialized tensors (weights)
std::cout<<"\n\n";
//Printing intermediate tensors
std::cout<<"\n\n";
//Checking if tensor already exist in model
std::cout<<"\n\nTensor \"16weight\" already exist: "<<std::boolalpha<<model.CheckIfTensorAlreadyExist("16weight")<<"\n\n";
std::vector<size_t> tensorShape = model.GetTensorShape("16weight");
std::cout<<"Shape of tensor \"16weight\": ";
for(auto& it:tensorShape){
std::cout<<it<<",";
}
std::cout<<"\n\nData type of tensor \"16weight\": ";
SOFIE::ETensorType tensorType = model.GetTensorType("16weight");
std::cout<<SOFIE::ConvertTypeToString(tensorType);
//Printing generated inference code
std::cout<<"\n\n";
model.PrintGenerated();
}
#define gROOT
Definition TROOT.h:406
RModel Parse(std::string filename, bool verbose=false)
const ETensorType & GetTensorType(std::string name)
Definition RModel.cxx:94
bool CheckIfTensorAlreadyExist(std::string tensor_name)
Definition RModel.cxx:122
void OutputGenerated(std::string filename="", bool append=false)
Definition RModel.cxx:1081
const std::vector< size_t > & GetTensorShape(std::string name)
Definition RModel.cxx:56
void Generate(std::underlying_type_t< Options > options, int batchSize=-1, long pos=0, bool verbose=false)
Definition RModel.cxx:703
Author
Sanjiban Sengupta

Definition in file TMVA_SOFIE_ONNX.C.