Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: [Fatal] (createNode) Unimplemented: node operation LinearClassifier #48

Open
pd-vt opened this issue Apr 19, 2024 · 3 comments
Open
Labels
operand missing ONNX operand not yet implemented in onnx2c

Comments

@pd-vt
Copy link

pd-vt commented Apr 19, 2024

Trying to generate model.c for very Simple classification model which just says input value is positive or negative. Please find attached model.onnx file inside the zip file.

model.zip

@kraiskil
Copy link
Owner

I'm looking at the list of ONNX operators: https://github.com/onnx/onnx/blob/main/docs/Operators.md, and there is no LinearClassifier. What is happening? How did you create that model?

@pd-vt
Copy link
Author

pd-vt commented Apr 20, 2024

The above attached model is been created using following simple python script. Our goal is to just make sure the microcontroller we have is capable to run such basic model and then if it is ok, we go for more complex system.

`

Import

import numpy as np
from sklearn.linear_model import LogisticRegression
from skl2onnx import convert_sklearn
from skl2onnx.common.data_types import FloatTensorType

Generate some sample data (numbers) and their corresponding labels

numbers = np.array([-2, -1, 0, 1, 2, 3, -3, -4, 5, -5])
labels = np.array(['negative', 'negative', 'positive', 'positive', 'positive', 'positive', 'negative', 'negative', 'positive', 'negative'])

Reshape the data for compatibility with Scikit-learn

numbers = numbers.reshape(-1, 1)

Initialize and train a logistic regression model

model = LogisticRegression()
model.fit(numbers, labels)

Define the input type for the ONNX model

initial_type = [('input', FloatTensorType([None, 1]))]

Convert the Scikit-learn model to ONNX format

onnx_model = convert_sklearn(model, initial_types=initial_type)

Save the ONNX model to a file

with open("model.onnx", "wb") as f:
f.write(onnx_model.SerializeToString())

`

@kraiskil
Copy link
Owner

Ah, seems there are two layers of ONNX, the base neural networks and on top of this classical ML operands. https://github.com/onnx/onnx/blob/main/docs/Overview.md

As of now, onnx2c has only considered the NN part of ONNX.

A quick look at ONNX-ML suggests the structure of the opearators are similar in ONNX-ML and ONNX-NN, so implementing ONNX-ML operands might not require (m)any changes to onnx2c internals.
I can't find any detailed info on the ML internals, nor any backend tests for the ML operands, though. But seeing the error in the title of this issue is encouraging - at least onnx2c hadn't crashed on ONNX-ML input...

Adding a new operand to onnx2c isn't too difficult. Much of the work would be to make a few tests for it, as ONNX doesn't provide any. PRs welcome :) https://github.com/kraiskil/onnx2c/blob/master/development.md#adding-a-new-nodeop-implementation

@kraiskil kraiskil added the operand missing ONNX operand not yet implemented in onnx2c label Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
operand missing ONNX operand not yet implemented in onnx2c
Projects
None yet
Development

No branches or pull requests

2 participants