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

XGboost conversion exception: Unable to guess objective in [] #474

Closed
shadimari opened this issue Jun 27, 2021 · 4 comments
Closed

XGboost conversion exception: Unable to guess objective in [] #474

shadimari opened this issue Jun 27, 2021 · 4 comments

Comments

@shadimari
Copy link

shadimari commented Jun 27, 2021

I am trying to convert the attached XGboost model, which was trained using XGboost v1.3-1 + binary:logistic + early_stopping. The conversion results in an exception due to the fact that the source code assumes it is a multi:* objective function rather than a binary:logistic.

if trees > ntrees > 0:
            state = booster.__getstate__()
            bstate = bytes(state['handle'])
            reg = re.compile(b'(multi:[a-z]{1,15})')
            objs = list(set(reg.findall(bstate)))
            if len(objs) != 1:
                raise RuntimeError(
                    "Unable to guess objective in {}.".format(objs))
            kwargs['num_class'] = trees // ntrees
            kwargs["objective"] = objs[0].decode('ascii')
        else:
            kwargs['num_class'] = 1
            kwargs["objective"] = "binary:logistic"

Source code as follows:

import pickle
import xgboost
from onnxmltools.convert.common import data_types
from onnxmltools.convert import convert_xgboost
from onnxmltools.utils import save_model

xgb_model_loaded = pickle.load(open('xgboost-model', "rb"))
num_features = len(xgb_model_loaded.feature_names)
initial_type = [('float_input', data_types.FloatTensorType([1, num_features]))]
model_onnx = convert_xgboost(xgb_model_loaded, initial_types=initial_type)

model.tar.gz

@shadimari
Copy link
Author

@xadupre I think this change has been introduced by you lately. would you please have a quick look?

@shadimari
Copy link
Author

@xadupre is there a chance you can quickly confirm this bug?

@xadupre
Copy link
Collaborator

xadupre commented Jul 13, 2021

Hi,

I modified your example into the following:

import pickle
import xgboost
from onnxmltools.convert.common import data_types
from onnxmltools.convert import convert_xgboost
from onnxmltools.utils import save_model

xgb_model_loaded = pickle.load(open('xgboost-model', "rb"))
num_features = xgb_model_loaded.num_features()
initial_type = [('float_input', data_types.FloatTensorType([None, num_features]))]
model_onnx = convert_xgboost(xgb_model_loaded, initial_types=initial_type)

But it needs PR #480 to work.

@shadimari
Copy link
Author

@xadupre many thanks for your support. The issue is fixed.

@xadupre xadupre closed this as completed Sep 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants