diff --git a/TrkOnlyPID/README.md b/TrkOnlyPID/README.md index df4b83e..c420c69 100644 --- a/TrkOnlyPID/README.md +++ b/TrkOnlyPID/README.md @@ -19,7 +19,8 @@ The python code provided in the file [TrkOnlyPIDTrain.py](TrkOnlyPIDTrain.py) is * generate plots to provide more information on the dataset, how the training went, and how the model perform Once the model is trained and the weights are saved in an ONNX file, this file can be used by TMVA:SOFIE to generate the inference code -that can be used in Offline (for details about this process, check [this documentation](https://github.com/Mu2e/MLTrain/blob/main/TrkQual/README.md#converting-a-model-for-use-in-offline)). +that can be used in Offline. +See `scripts/CreateInference.C` to create this model. ## Version history diff --git a/TrkPID/README.md b/TrkPID/README.md index 38864e3..dfc1075 100644 --- a/TrkPID/README.md +++ b/TrkPID/README.md @@ -19,7 +19,8 @@ The python code provided in the file [TrackPIDTrain.py](TrackPIDTrain.py) is use * generate plots to provide more information on the dataset, how the training went, and how the model perform Once the model is trained and the weights are saved in an ONNX file, this file can be used by TMVA:SOFIE to generate the inference code -that can be used in Offline (for details about this process, check [this documentation](https://github.com/Mu2e/MLTrain/blob/main/TrkQual/README.md#converting-a-model-for-use-in-offline)). +that can be used in Offline. +See `scripts/CreateInference.C` to create this model. ## Version history diff --git a/scripts/CreateInference.C b/scripts/CreateInference.C new file mode 100644 index 0000000..6a9f525 --- /dev/null +++ b/scripts/CreateInference.C @@ -0,0 +1,29 @@ +/// \file +/// \ingroup tutorial_tmva +/// \notebook -nodraw +/// This macro parses a .onnx file +/// into RModel object and further generating the .hxx header files for inference. +/// +/// \macro_code +/// \macro_output +/// \author Sanjiban Sengupta +/// modified by A. Edmonds (2025) + +#include "TMVA/RModel.hxx" +#include "TMVA/RModelParser_ONNX.hxx" +#include + +using namespace TMVA::Experimental; + +// Create a TMVA::SOFIE model from an ONNX model +void CreateInference(std::string modelname = "model.onnx", std::string infername = "model.hxx"){ + + SOFIE::RModelParser_ONNX parser; + SOFIE::RModel model = parser.Parse(modelname, true); + + //Generating inference code + model.Generate(); + + // Write the code in a file (e.g. model.hxx, model.dat) + model.OutputGenerated(infername); +}