Draft: ONNX setup and tester
First setup of an algorithm (for testing?) ONNX / ONNXRuntime for generalized ML inference infrastructure, see #460.
Also adds possibility of using it as a functor (both for inputs and evaluation).
Goes with LHCb!4069 (closed).
Model / training
For now has some simple 100 neuron 1 hidden layer MLP that uses some info available in ProtoParticle for electron vs. pion PID. This shows how easy it will be to add such a thing to your algorithm. Also from the training side there are a lot of converters to ONNX for a lot of packages and their models (also non-NN models, like decision trees, etc...). For this case it was as simple as adding (using skl2onnx package for Scikit-learn):
# Convert into ONNX format
from skl2onnx import convert_sklearn
from skl2onnx.common.data_types import FloatTensorType
initial_types = [('float_input', FloatTensorType([None, len(obs)]))]
onx = convert_sklearn(mva, initial_types=initial_types, target_opset=17, options={id(mva): {'zipmap': False}})
with open("chargedpidwithonnx.onnx", "wb") as f:
f.write(onx.SerializeToString())