This is a summary of functions this modules provides.

ONNX converters

Write ONNX graphs

ONNX runtime

ONNX validation, benchmark, tools

Outside ONNX world

This was a first experiment to play with machine learning: convert a model into C code. A similar way than ONNX but far less advanced.


from sklearn.linear_model import LogisticRegression
from sklearn.datasets import load_iris

iris = load_iris()
X = iris.data[:, :2]
y = iris.target
y[y == 2] = 1
lr = LogisticRegression()
lr.fit(X, y)

# Conversion into a graph.
from mlprodict.grammar.grammar_sklearn import sklearn2graph
gr = sklearn2graph(lr, output_names=['Prediction', 'Score'])

# Conversion into C
ccode = gr.export(lang='c')
# We print after a little bit of cleaning (remove all comments)
print("\n".join(_ for _ in ccode['code'].split("\n") if "//" not in _))


    int LogisticRegression (float* pred, float* Features)
        float pred0c0c00c0[2] = {(float)3.3882975578308105, (float)-3.164527654647827};
        float* pred0c0c00c1 = Features;
        float pred0c0c00;
        adot_float_float(&pred0c0c00, pred0c0c00c0, pred0c0c00c1, 2);
        float pred0c0c01 = (float)-8.323304176330566;
        float pred0c0c0 = pred0c0c00 + pred0c0c01;
        float pred0c0;
        sign_float(&pred0c0, pred0c0c0);
        float pred0[2];
        concat_float_float(pred0, pred0c0, pred0c0c0);
        memcpy(pred, pred0, 2*sizeof(float));
        return 0;