onnxmltools icon indicating copy to clipboard operation
onnxmltools copied to clipboard

convert_xgboost - AssertionError: Missing required property "tree_info".

Open ShuningL opened this issue 1 year ago • 8 comments

I was trying to run the sample code of convert_xgboost(onnxmltools/docs/examples/plot_convert_xgboost.py), and I got an error ["AssertionError: Missing required property "tree_info".] which is only for Dmatrix ( for sklearn model, it's ok). Looking forward to your responses.

------------------------- The Output is as follow ----------------------------

XGBClassifier(base_score=0.5, booster='gbtree', colsample_bylevel=1, colsample_bynode=1, colsample_bytree=1, gamma=0, gpu_id=-1, importance_type='gain', interaction_constraints='', learning_rate=0.300000012, max_delta_step=0, max_depth=6, min_child_weight=1, missing=nan, monotone_constraints='()', n_estimators=100, n_jobs=0, num_parallel_tree=1, objective='multi:softprob', random_state=0, reg_alpha=0, reg_lambda=1, scale_pos_weight=None, subsample=1, tree_method='exact', validate_parameters=1, verbosity=None) [1 2 2 0 2 0 0 1 0 1 1 2 2 1 2 2 2 2 2 2 0 1 2 0 2 1 1 0 2 2 2 1 2 0 0 2 2 2]

AssertionError Traceback (most recent call last) Input In [10], in <cell line: 71>() 68 bst = train_xgb(param, dtrain, 10) 70 initial_type = [('float_input', FloatTensorType([None, 4]))] ---> 71 onx = convert_xgboost(bst, initial_types=initial_type) 73 sess = rt.InferenceSession(onx.SerializeToString()) 74 input_name = sess.get_inputs()[0].name

File ~/miniconda3/envs/mlflow/lib/python3.8/site-packages/onnxmltools/convert/main.py:177, in convert_xgboost(*args, **kwargs) 174 raise RuntimeError('xgboost is not installed. Please install xgboost to use this feature.') 176 from .xgboost.convert import convert --> 177 return convert(*args, **kwargs)

File ~/miniconda3/envs/mlflow/lib/python3.8/site-packages/onnxmltools/convert/xgboost/convert.py:39, in convert(model, name, initial_types, doc_string, target_opset, targeted_onnx, custom_conversion_functions, custom_shape_calculators) 36 name = str(uuid4().hex) 38 if isinstance(model, xgboost.Booster): ---> 39 model = WrappedBooster(model) 40 target_opset = target_opset if target_opset else get_maximum_opset_supported() 41 topology = parse_xgboost(model, initial_types, target_opset, custom_conversion_functions, custom_shape_calculators)

File ~/miniconda3/envs/mlflow/lib/python3.8/site-packages/onnxmltools/convert/xgboost/parse.py:85, in WrappedBooster.init(self, booster) 83 def init(self, booster): 84 self.booster = booster ---> 85 self.kwargs = get_attributes(booster) 87 if self.kwargs['num_class'] > 0: 88 self.classes = self._generate_classes(self.kwargs)

File ~/miniconda3/envs/mlflow/lib/python3.8/site-packages/onnxmltools/convert/xgboost/_parse.py:35, in _get_attributes(booster) 33 reg = re.compile(b'("tree_info":\[[0-9,]*\])') 34 objs = list(set(reg.findall(bstate))) ---> 35 assert len(objs) == 1, 'Missing required property "tree_info".' 36 tree_info = json.loads("{{{}}}".format(objs[0].decode('ascii')))['tree_info'] 37 num_class = len(set(tree_info))

AssertionError: Missing required property "tree_info".

---------------------------------------------------------------

ShuningL avatar Jan 04 '23 09:01 ShuningL