Question/Issue:
Hello, I’m trying to upload simple model to edge impulse directly. But It can not be uploaded by direct model upload menu from my project. How could I upload my model?
The code below is what I am trying.
Project ID:
(onnx_upload_test - Pretrained model - Edge Impulse
Context/Use case:
import numpy as np
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from sklearn.svm import SVC
from skl2onnx import convert_sklearn
from skl2onnx.common.data_types import FloatTensorType
Sample data for training
X_train = np.array([[1, 2, 3, 4, 5], [2, 3, 4, 5, 6], [3, 4, 5, 1, 2], [4, 5, 6, 7, 8], [5, 6, 7, 8, 9]])
y_train = np.array([0, 1, 2, 0, 1])
Create the pipeline
pipeline = Pipeline([
(‘scaler’, StandardScaler()), # StandardScaler
(‘svc’, SVC()) # SVC with probability
])
Fit the model
pipeline.fit(X_train, y_train)
evaluation
pipeline.fit(X_train, y_train)
X_test = np.array([[1, 2, 3, 4, 5], [3, 4, 5, 1, 2], [5, 6, 7, 8, 9], [4, 5, 6, 7, 8]])
y_test = np.array([0, 2, 1, 0])
print((X_test))
print((pipeline.named_steps[‘scaler’].transform(X_test)))
print(pipeline.predict(X_test))
score = pipeline.score(X_test, y_test)
print(“pipeline score:”, score)
Convert the pipeline to ONNX
Set the input shape to a fixed size (e.g., [1, 5] for batch size of 1)
initial_type = [(‘float_input’, FloatTensorType([1, 5]))]
final_types = [(‘output_label’, FloatTensorType([1, 1])), (‘output_probability’, FloatTensorType([1, 1]))]
onnx_model = convert_sklearn(pipeline, initial_types=initial_type, final_types= final_types)
Save the ONNX model
with open(‘svc_pipeline.onnx’, ‘wb’) as f:
f.write(onnx_model.SerializeToString())
Steps Taken:
- making pipeline model
- making onnx file from the code
- upload onnx file to the project
Expected Outcome:
simply upload
Actual Outcome:
Creating job… OK (ID: 25546624)
Scheduling job in cluster…
Container image pulled!
Job started
Converting ONNX model…
Scheduling job in cluster…
Job started
INFO: No representative features passed in, won’t quantize this model
Trying conversion using onnx2tf…
Grabbing input information…
No input shape conversion needed
ERROR: Scaler OP is not yet implemented.
Grabbing input information OK
Conversion using onnx2tf failed
Trying conversion using onnx-tf…
Traceback (most recent call last):
File “convert-via-tf-onnx.py”, line 68, in
ei_tensorflow.model_conversion.onnx.onnx_to_tflite(args.onnx_file, file_float32, file_int8,
File “/app/./resources/libraries/ei_tensorflow/model_conversion/onnx.py”, line 77, in onnx_to_tflite
onnx.checker.check_model(onnx_graph)
File “/app/.venv-onnx-tf/lib/python3.8/site-packages/onnx/checker.py”, line 106, in check_model
C.check_model(protobuf_string)
onnx.onnx_cpp2py_export.checker.ValidationError: Your model ir_version is higher than the checker’s.
Conversion using onnx-tf also failed, cannot use this ONNX file - contact your solutions engineer, or post the logs on the forum.
Application exited with code 1
Converting ONNX model failed, see above
Job failed (see above)
Reproducibility:
- [O] Always
- [ ] Sometimes
- [ ] Rarely
Environment:
- Just website
Additional Information:
Nothing