onnxmltools icon indicating copy to clipboard operation
onnxmltools copied to clipboard

convert_xgboost fails with JSONDecodeError

Open hombit opened this issue 1 year ago • 0 comments

Env

  • Python 3.9.7
  • xgboost 1.5.2
  • onnxmltools 1.11.0

Code to reproduce

import xgboost
from onnxmltools.convert import convert_xgboost
from onnxmltools.convert.common.data_types import FloatTensorType

model = xgboost.XGBClassifier()
model.load_model("xgb.ubj")
convert_xgboost(model, initial_types=[('input', FloatTensorType(shape=[None, None]))])

Data

xgb.ubj: https://drive.google.com/file/d/1KaFC-AFBluTO1CJLD1XAFZEQrUnRpkAx/view?usp=share_link

Error

JSONDecodeError: Expecting value: line 138 column 75 (char 12602)

Full Traceback

Expand ``` ~/.conda/envs/env/lib/python3.9/site-packages/onnxmltools/convert/main.py in convert_xgboost(*args, **kwargs) 175 176 from .xgboost.convert import convert --> 177 return convert(*args, **kwargs) 178 179

~/.conda/envs/env/lib/python3.9/site-packages/onnxmltools/convert/xgboost/convert.py in convert(model, name, initial_types, doc_string, target_opset, targeted_onnx, custom_conversion_functions, custom_shape_calculators) 41 topology = parse_xgboost(model, initial_types, target_opset, custom_conversion_functions, custom_shape_calculators) 42 topology.compile() ---> 43 onnx_model = convert_topology(topology, name, doc_string, target_opset, targeted_onnx) 44 return onnx_model

~/.conda/envs/env/lib/python3.9/site-packages/onnxconverter_common/topology.py in convert_topology(topology, model_name, doc_string, target_opset, targeted_onnx, channel_first_inputs) 774 else: 775 # Convert the selected operator into some ONNX objects and save them into the container --> 776 get_converter(operator.type)(scope, operator, container) 777 778 # When calling ModelComponentContainer's add_initializer(...), nothing is added into the input list.

~/.conda/envs/env/lib/python3.9/site-packages/onnxmltools/convert/xgboost/operator_converters/XGBoost.py in convert_xgboost(scope, operator, container) 299 cls = XGBRegressorConverter 300 cls.validate(xgb_node) --> 301 cls.convert(scope, operator, container) 302 303

~/.conda/envs/env/lib/python3.9/site-packages/onnxmltools/convert/xgboost/operator_converters/XGBoost.py in convert(scope, operator, container) 224 inputs = operator.inputs 225 --> 226 objective, base_score, js_trees = XGBConverter.common_members(xgb_node, inputs) 227 228 params = XGBConverter.get_xgb_params(xgb_node)

~/.conda/envs/env/lib/python3.9/site-packages/onnxmltools/convert/xgboost/operator_converters/XGBoost.py in common_members(xgb_node, inputs) 40 # XGBoost 0.7 was the first version released with it. 41 js_tree_list = booster.get_dump(with_stats=True, dump_format='json') ---> 42 js_trees = [json.loads(s) for s in js_tree_list] 43 return objective, base_score, js_trees 44

~/.conda/envs/env/lib/python3.9/site-packages/onnxmltools/convert/xgboost/operator_converters/XGBoost.py in (.0) 40 # XGBoost 0.7 was the first version released with it. 41 js_tree_list = booster.get_dump(with_stats=True, dump_format='json') ---> 42 js_trees = [json.loads(s) for s in js_tree_list] 43 return objective, base_score, js_trees 44

~/.conda/envs/env/lib/python3.9/json/init.py in loads(s, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw) 344 parse_int is None and parse_float is None and 345 parse_constant is None and object_pairs_hook is None and not kw): --> 346 return _default_decoder.decode(s) 347 if cls is None: 348 cls = JSONDecoder

~/.conda/envs/env/lib/python3.9/json/decoder.py in decode(self, s, _w) 335 336 """ --> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end()) 338 end = _w(s, end).end() 339 if end != len(s):

~/.conda/envs/env/lib/python3.9/json/decoder.py in raw_decode(self, s, idx) 353 obj, end = self.scan_once(s, idx) 354 except StopIteration as err: --> 355 raise JSONDecodeError("Expecting value", s, err.value) from None 356 return obj, end

JSONDecodeError: Expecting value: line 138 column 75 (char 12602)

</details>

hombit avatar Nov 30 '22 04:11 hombit