Open maoding opened 1 year ago
Is this package dead or something? I also have this error just trying to reproduce the basic sample on the readme.
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
import numpy as np
iris = load_iris()
Xi, yi = iris.data, iris.target
X_train, X_test, y_train, y_test = train_test_split(Xi, yi)
from sklearn.linear_model import LogisticRegression
clr = LogisticRegression(max_iter=1000)
clr.fit(X_train, y_train)
from skl2onnx import convert_sklearn
from skl2onnx.common.data_types import FloatTensorType
initial_type = [('float_input', FloatTensorType([None, 4]))]
#onx = convert_sklearn(clr, initial_types=initial_type)
onx = to_onnx(clr, X=X_train, verbose=1)
with open("logreg_iris.onnx", "wb") as f:
f.write(onx.SerializeToString())
import onnxruntime as rt
sess = rt.InferenceSession("logreg_iris.onnx", providers=["CPUExecutionProvider"])
input_name = sess.get_inputs()[0].name
label_name = sess.get_outputs()[0].name
pred_onx = sess.run([label_name], {input_name: X_test.astype(np.float32)})[0]
pred_onx
InvalidGraph: [ONNXRuntimeError] : 10 : INVALID_GRAPH : Load model from logreg_iris.onnx failed:This is an invalid model. Type Error: Type 'tensor(double)' of input parameter (probabilities) of operator (ZipMap) in node (ZipMap) is invalid.
Sorry for the delay, the package is not dead. ZipMap only works with float32 not double (float64). You need to remove it to_onnx(clr, X=X_train, options={'zipmap': False})
or to switch to float32 to_onnx(clr, X=X_train.astype(np.float32), verbose=1)
.
Here is a simple example using a regression and
to_onnx
.(I manipulate one column to be of type
int
instead ofstr
. - Actually this doesn't matter.)I am able to save the model as onnx but on creating an
onnxruntime.InferenceSession
I getONNXRuntimeError
(see below).What am I doing wrong?
Used versions: