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

convert XGBRegressor( booster='gblinear', objective='reg:squarederror') to ONNX returns error #633

Open
devspatron opened this issue Jul 27, 2023 · 0 comments

Comments

@devspatron
Copy link

devspatron commented Jul 27, 2023

Hi fellow developers, i was working on a simple 3d regressor model and i used the following parameters

#my code extract:

from mlprodict.onnxrt import OnnxInference
import numpy
import onnxruntime as onnx_RT
from sklearn.datasets import load_iris, load_diabetes, make_classification
from sklearn.model_selection import train_test_split
from sklearn.pipeline import Pipeline
from sklearn.preprocessing import StandardScaler
from xgboost import XGBClassifier, XGBRegressor, DMatrix, train as train_xgb
from skl2onnx.common.data_types import FloatTensorType
from skl2onnx import convert_sklearn, to_onnx, update_registered_converter
from skl2onnx.common.shape_calculator import (
    calculate_linear_classifier_output_shapes,
    calculate_linear_regressor_output_shapes)
from onnxmltools.convert.xgboost.operator_converters.XGBoost import (
    convert_xgboost)
from onnxmltools.convert import convert_xgboost as convert_xgboost_booster

data = load_iris()
X = data.data[:, :2]
y = data.target

ind = numpy.arange(X.shape[0])
numpy.random.shuffle(ind)
X = X[ind, :].copy()
y = y[ind].copy()

models_01 = XGBRegressor(  booster='gblinear', objective='reg:squarederror')
models_01.fit(X, y)

**#Register the converter for XGBRegressor**
    update_registered_converter(
        XGBRegressor, 'XGBoostXGBRegressor',
        calculate_linear_regressor_output_shapes, convert_xgboost,
        options={'nocl': [True, True], 'zipmap': [False, False, 'columns']}
        )

**#convert to ONNX**
  onnx_result = convert_sklearn( models_01, "My_simple_XGBRegressor",
      [('input', FloatTensorType([None, X.shape[1]  ]))],
      target_opset={'': 12, 'ai.onnx.ml': 2}, options={'zipmap': False},
      )

I then tried to convert to load an inference session but it always returned the following error.....

#test the ONNX model
onnx_model_inference = onnx_RT.InferenceSession( onnx_result.SerializeToString() ) #throws an error

#the error
InvalidGraph: [ONNXRuntimeError] : 10 : INVALID_GRAPH : Load model from models_01.onnx failed: This is an invalid model. In Node, ("TreeEnsembleRegressor", TreeEnsembleRegressor, "ai.onnx.ml", -1) : ("input": tensor(float),) -> ("variable": tensor(float),) , Error Attribute 'nodes_falsenodeids' is expected to have field 'ints'
#the error

please help... Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant