# Export TMVA MLP to ONNX

**URL:** <https://root-forum.cern.ch/t/export-tmva-mlp-to-onnx/61781>\
**Category:** TMVA\
**Created:** [September 25, 2024, 9:35am UTC](https://root-forum.cern.ch/t/export-tmva-mlp-to-onnx/61781 "2024-09-25T09:35:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![martinh](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/848f3c/32.png) [@martinh](https://root-forum.cern.ch/u/martinh)\
**Post date:** [September 25, 2024, 9:35am UTC](https://root-forum.cern.ch/t/export-tmva-mlp-to-onnx/61781/1 "2024-09-25T09:35:54Z")

</div>

Hello!

I have trained a TMVA Multilayer Perceptron (MLP) but would now like to export the trained classifier for preservation. There are extensive possibilities to _import_ classifiers from Keras, ONNX, … to TMVA using SOFIE. But it doesn’t seem to support _ex_porting. It only seems to be possible to save trained classifiers as XML (to be read with TMVA) or C classes. It would however be much interoperable if there was an option to export directly to the logic of other machine-learning tools, ideally ONNX.

Is anyone aware of how to do this directly from TMVA or, if need be, using an external tool?

Thanks for your help!  
Martin

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [September 25, 2024, 5:55pm UTC](https://root-forum.cern.ch/t/export-tmva-mlp-to-onnx/61781/2 "2024-09-25T17:55:08Z")

</div>

Hi Martin,

Thanks for the post and welcome to the ROOT Community!

I do not think this is natively supported, but @moneta could have a proposal.

Cheers,  
Danilo

---

<div class="post-metadata">

**Author:** ![martinh](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/m/848f3c/32.png) [@martinh](https://root-forum.cern.ch/u/martinh)\
**Post date:** [April 28, 2025, 8:38am UTC](https://root-forum.cern.ch/t/export-tmva-mlp-to-onnx/61781/3 "2025-04-28T08:38:28Z")

</div>

Hi!

Given this currently seems to be a gap in functionality, I’ve cooked up a [small script](https://gitlab.com/hepcedar/petrify-bdt/-/blob/master/petrifybdt/tmvamlp.py) that reads in a TMVA `.xml` with Keras and then exports it to `.onnx`.

Just it in case that’s of use to anyone else: it lives in the [petrify-bdt](https://gitlab.com/hepcedar/petrify-bdt/) git repository and can be executed as  
`python3 tmvamlp.py <weights file>.xml`

Cheers,  
Martin
