Commit da5fba1
committed
[tmva][sofie] Migrate SOFIE tutorials from Keras to PyTorch and ONNX
PyTorch has become the dominant training framework in the particle
physics community, and it comes with better ONNX support than Keras.
Since ONNX is the primary input format for SOFIE, the SOFIE tutorials
based on the Higgs dataset are migrated from Keras to PyTorch with
ONNX export.
Replace TMVA_SOFIE_Keras_HiggsModel.py with
TMVA_SOFIE_PyTorch_HiggsModel.py, which trains the same architecture
(7 -> 64 -> 64 -> 1 with sigmoid output, binary cross-entropy, Adam,
5 epochs) with PyTorch, exports it to HiggsModel.onnx and generates
the inference code with RModelParser_ONNX. The generated code is
validated against the PyTorch predictions, and the trained model was
checked to be roughly equivalent to the Keras one (test AUC 0.712 vs.
0.720 on an identical data split).
Adapt the downstream tutorials that consume the trained Higgs model
(TMVA_SOFIE_RDataFrame.C/.py, TMVA_SOFIE_RDataFrame_JIT.C,
TMVA_SOFIE_RSofieReader.C, TMVA_SOFIE_Inference.py) to use
HiggsModel.onnx instead of HiggsModel.keras. Also migrate
TMVA_SOFIE_Models.py, which demonstrates storing several models in a
single generated header with weights in one ROOT binary file: this
feature is independent of the training framework.
The PyTorch ONNX export and ROOT's SOFIE parser are usually linked
against different protobuf versions, so the training and export run
in a separate Python process, following the pattern established in
TMVA_SOFIE_ONNX.py.
The CMake test dependencies are updated accordingly, and the migrated
tutorials are now gated on tmva-sofie plus the torch and onnx Python
modules instead of keras.
🤖 Done with the help of AI.1 parent 39e4fb2 commit da5fba1
11 files changed
Lines changed: 442 additions & 270 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
179 | | - | |
180 | 179 | | |
181 | 180 | | |
| 181 | + | |
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
370 | 370 | | |
371 | 371 | | |
372 | 372 | | |
373 | | - | |
374 | | - | |
375 | | - | |
376 | | - | |
377 | | - | |
378 | | - | |
379 | | - | |
380 | | - | |
381 | 373 | | |
382 | 374 | | |
383 | 375 | | |
384 | 376 | | |
| 377 | + | |
385 | 378 | | |
386 | 379 | | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
387 | 387 | | |
388 | 388 | | |
389 | 389 | | |
| |||
655 | 655 | | |
656 | 656 | | |
657 | 657 | | |
658 | | - | |
| 658 | + | |
659 | 659 | | |
660 | 660 | | |
661 | 661 | | |
| |||
848 | 848 | | |
849 | 849 | | |
850 | 850 | | |
851 | | - | |
852 | | - | |
| 851 | + | |
| 852 | + | |
853 | 853 | | |
854 | 854 | | |
855 | 855 | | |
| |||
947 | 947 | | |
948 | 948 | | |
949 | 949 | | |
950 | | - | |
951 | | - | |
952 | | - | |
953 | 950 | | |
954 | 951 | | |
955 | 952 | | |
956 | 953 | | |
957 | 954 | | |
958 | 955 | | |
959 | 956 | | |
| 957 | + | |
960 | 958 | | |
| 959 | + | |
961 | 960 | | |
962 | 961 | | |
963 | 962 | | |
| |||
966 | 965 | | |
967 | 966 | | |
968 | 967 | | |
969 | | - | |
970 | 968 | | |
971 | 969 | | |
972 | 970 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | | - | |
7 | | - | |
| 6 | + | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | | - | |
30 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
31 | 32 | | |
32 | | - | |
33 | | - | |
| 33 | + | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
40 | | - | |
| 41 | + | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | 45 | | |
50 | 46 | | |
51 | 47 | | |
| |||
Lines changed: 0 additions & 164 deletions
This file was deleted.
0 commit comments