{ "cells": [ { "cell_type": "markdown", "id": "efb09f11", "metadata": {}, "source": [ "# TMVA_SOFIE_ONNX\n", "This macro provides a simple example for the parsing of ONNX files into\n", "RModel object and further generating the .hxx header files for inference.\n", "\n", "\n", "\n", "**Author:** Sanjiban Sengupta \n", "This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:23 PM." ] }, { "cell_type": "code", "execution_count": null, "id": "d0b18cd7", "metadata": { "collapsed": false }, "outputs": [], "source": [ "using namespace TMVA::Experimental;" ] }, { "cell_type": "markdown", "id": "06a290c9", "metadata": {}, "source": [ " Arguments are defined. " ] }, { "cell_type": "code", "execution_count": null, "id": "b0c96d4d", "metadata": { "collapsed": false }, "outputs": [], "source": [ "std::string inputFile = \"\";" ] }, { "cell_type": "code", "execution_count": null, "id": "dc4693c0", "metadata": { "collapsed": false }, "outputs": [], "source": [ "if (inputFile.empty() )\n", " inputFile = std::string(gROOT->GetTutorialsDir()) + \"/machine_learning/Linear_16.onnx\";" ] }, { "cell_type": "markdown", "id": "c57ea89d", "metadata": {}, "source": [ "Creating parser object to parse ONNX files" ] }, { "cell_type": "code", "execution_count": null, "id": "84b8b5de", "metadata": { "collapsed": false }, "outputs": [], "source": [ " SOFIE::RModelParser_ONNX parser;\n", " SOFIE::RModel model = parser.Parse(inputFile, true);" ] }, { "cell_type": "markdown", "id": "79ac7848", "metadata": {}, "source": [ "Generating inference code" ] }, { "cell_type": "code", "execution_count": null, "id": "93ee2422", "metadata": { "collapsed": false }, "outputs": [], "source": [ " model.Generate();" ] }, { "cell_type": "markdown", "id": "54a5f430", "metadata": {}, "source": [ "write the code in a file (by default Linear_16.hxx and Linear_16.dat" ] }, { "cell_type": "code", "execution_count": null, "id": "0b7c329c", "metadata": { "collapsed": false }, "outputs": [], "source": [ " model.OutputGenerated();" ] }, { "cell_type": "markdown", "id": "53ef8148", "metadata": {}, "source": [ "Printing required input tensors" ] }, { "cell_type": "code", "execution_count": null, "id": "a84c54ed", "metadata": { "collapsed": false }, "outputs": [], "source": [ " model.PrintRequiredInputTensors();" ] }, { "cell_type": "markdown", "id": "2c2e8f1c", "metadata": {}, "source": [ "Printing initialized tensors (weights)" ] }, { "cell_type": "code", "execution_count": null, "id": "aef6102e", "metadata": { "collapsed": false }, "outputs": [], "source": [ " std::cout<<\"\\n\\n\";\n", " model.PrintInitializedTensors();" ] }, { "cell_type": "markdown", "id": "0321524a", "metadata": {}, "source": [ "Printing intermediate tensors" ] }, { "cell_type": "code", "execution_count": null, "id": "2ff643d8", "metadata": { "collapsed": false }, "outputs": [], "source": [ " std::cout<<\"\\n\\n\";\n", " model.PrintIntermediateTensors();" ] }, { "cell_type": "markdown", "id": "6058fee7", "metadata": {}, "source": [ "Checking if tensor already exist in model" ] }, { "cell_type": "code", "execution_count": null, "id": "08a75c2f", "metadata": { "collapsed": false }, "outputs": [], "source": [ " std::cout<<\"\\n\\nTensor \\\"16weight\\\" already exist: \"< tensorShape = model.GetTensorShape(\"16weight\");\n", " std::cout<<\"Shape of tensor \\\"16weight\\\": \";\n", " for(auto& it:tensorShape){\n", " std::cout<