You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tmva/sofie/README.md
+39-28
Original file line number
Diff line number
Diff line change
@@ -18,57 +18,68 @@ Build ROOT with the cmake option tmva-sofie enabled.
18
18
cmake ../root -Dtmva-sofie=ON
19
19
make -j8
20
20
```
21
-
21
+
22
22
## Usage
23
23
SOFIE works in a parser-generator working architecture. With SOFIE, the user gets an [ONNX](https://github.com/root-project/root/tree/master/tmva/sofie_parsers), [Keras](https://github.com/root-project/root/blob/master/tmva/pymva/src/RModelParser_Keras.cxx) and a [PyTorch](https://github.com/root-project/root/blob/master/tmva/pymva/src/RModelParser_PyTorch.cxx) parser for translating models in respective formats into SOFIE's internal representation.
24
24
25
25
From ROOT command line, or in a ROOT macro, we can proceed with an ONNX model:
26
26
27
-
using namespace TMVA::Experimental;
28
-
SOFIE::RModelParser_ONNX parser;
29
-
SOFIE::RModel model = parser.Parse(“./example_model.onnx”);
30
-
model.Generate();
31
-
model.OutputGenerated(“./example_output.hxx”);
27
+
```c++
28
+
usingnamespaceTMVA::Experimental;
29
+
SOFIE::RModelParser_ONNX parser;
30
+
SOFIE::RModel model = parser.Parse(“./example_model.onnx”);
31
+
model.Generate();
32
+
model.OutputGenerated(“./example_output.hxx”);
33
+
```
32
34
33
35
And an C++ header file and a `.dat` file containing the model weights will be generated. You can also use
34
36
35
-
model.PrintRequiredInputTensors();
37
+
```c++
38
+
model.PrintRequiredInputTensors();
39
+
```
36
40
37
41
to check the required size and type of input tensor for that particular model, and use
38
42
39
-
model.PrintInitializedTensors();
43
+
```c++
44
+
model.PrintInitializedTensors();
45
+
```
40
46
41
47
to check the tensors (weights) already included in the model.
42
48
43
49
To use the generated inference code:
44
50
45
-
#include "example_output.hxx"
46
-
float input[INPUT_SIZE];
51
+
```c++
52
+
#include"example_output.hxx"
53
+
float input[INPUT_SIZE];
54
+
std::vector<float> out = TMVA_SOFIE_example_model::infer(input);
47
55
48
-
// Generated header file shall contain a Session class which requires initialization to load the corresponding weights.
// Once instantiated the session object's infer method can be used
52
-
std::vector<float> out = s.infer(input);
59
+
// Once instantiated the session object's infer method can be used
60
+
std::vector<float> out = s.infer(input);
61
+
```
62
+
63
+
With the default settings, the weights are contained in a separate binary file, but if the user instead wants them to be in the generated header file itself, they can use approproiate generation options.
53
64
54
-
With the default settings, the weights are contained in a separate binary file, but if the user instead wants them to be in the generated header file itself, they can use approproiate generation options.
55
-
56
-
model.Generate(Options::kNoWeightFile);
65
+
```c++
66
+
model.Generate(Options::kNoWeightFile);
67
+
```
57
68
58
-
Other such options includes `Options::kNoSession` (for not generating the Session class, and instead keeping the infer function independent).
69
+
Other such options includes `Options::kNoSession` (for not generating the Session class, and instead keeping the infer function independent).
59
70
SOFIE also supports generating inference code with RDataFrame as inputs, refer to the tutorials below for examples.
0 commit comments