This macro provides an example of using a trained model with Keras and make inference using SOFIE with the RSofieReader class This macro uses as input a Keras model generated with the TMVA_Higgs_Classification.C tutorial You need to run that macro before to generate the trained Keras model
Execute in this order:
root TMVA_Higgs_Classification.C
root TMVA_SOFIE_RSofieReader.C
void TMVA_SOFIE_RSofieReader(){
std::vector<float> input = {0.1,0.2,0.3,0.4,0.5,0.6,0.7};
auto output = model.Compute(input);
std::cout << "Event prediction = " << output[0] << std::endl;
std::string inputFileName = "Higgs_data.root";
std::string inputFile = std::string{
gROOT->GetTutorialDir()} +
"/machine_learning/data/" + inputFileName;
{"m_jj", "m_jjj", "m_lv", "m_jlv", "m_bb", "m_wbb", "m_wwbb"})
.Define("y","DNN_Values[0]")
.Histo1D({"h_sig", "", 100, 0, 1}, "y");
{"m_jj", "m_jjj", "m_lv", "m_jlv", "m_bb", "m_wbb", "m_wwbb"})
.Define("y","DNN_Values[0]")
.Histo1D({"h_bkg", "", 100, 0, 1}, "y");
h2->DrawClone();
}
ROOT's RDataFrame offers a modern, high-level interface for analysis of data stored in TTree ,...
TMVA::RSofieReader class for reading external Machine Learning models in ONNX files,...
auto Compute(F &&f) -> Internal::ComputeHelper< std::make_index_sequence< N >, T, F >
Helper to pass TMVA model to RDataFrame.Define nodes.
input model type is Keras
Parsing SOFIE model HiggsModel of type keras
generating the code with batch size = 1 ...
executing python3 -c ......
"""
import ROOT
model = ROOT.TMVA.Experimental.SOFIE.PyKeras.Parse('HiggsModel.keras',1)
model.Generate(ROOT.TMVA.Experimental.SOFIE.Options.kDefault,1, 0, 1)
model.OutputGenerated('HiggsModel_fromRSofieR.hxx');
model.PrintRequiredInputTensors()
model.PrintIntermediateTensors()
model.PrintOutputTensors()
"""
Model Header file is generated!
compile generated code from file HiggsModel_fromRSofieR.hxx
- Author
- Lorenzo Moneta
Definition in file TMVA_SOFIE_RSofieReader.C.