如何将LightGBM型号转换为ONXX?
我正在尝试保存我的模型,以便可以在ASP.NET程序中使用,我认为ONNX是一个很好的方法。问题在于,即使在检查文档并整天搜索搜索后,我仍然会遇到相同的错误提高ValueError('需要初始类型。 ..) in skl2onnx.convert for details
. I have no idea what's going on and any help is greatly appreciated!
My Code
import onnxmltools
from skl2onnx import convert
import lightgbm as lgb
import pandas as pd
parameters = {
'boosting': 'gbdt',
'feature_fraction': 0.5,
'bagging_fraction': 0.5,
'bagging_freq': 20,
'num_boost_round': 10000,
'verbose': -1 #maybe?
}
model_lgbm = lgb.train(parameters, train_data, valid_sets = test_data, early_stopping_rounds = 200);
onnx_model = convert.convert_sklearn(model_lgbm, ???);
I'm trying to save my model so it can be used in a ASP.NET program, and I think that ONNX is a good way to do so. The problem is that even after checking the docs and googling it all day, I still get the same error raise ValueError('Initial types are required. See usage of ' ValueError: Initial types are required. See usage of convert(...) in skl2onnx.convert for details
. I have no idea what's going on and any help is greatly appreciated!
My Code
import onnxmltools
from skl2onnx import convert
import lightgbm as lgb
import pandas as pd
parameters = {
'boosting': 'gbdt',
'feature_fraction': 0.5,
'bagging_fraction': 0.5,
'bagging_freq': 20,
'num_boost_round': 10000,
'verbose': -1 #maybe?
}
model_lgbm = lgb.train(parameters, train_data, valid_sets = test_data, early_stopping_rounds = 200);
onnx_model = convert.convert_sklearn(model_lgbm, ???);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为
您必须使用:
onnxmltools.convert_lightgbm
而不是
convert.convert_sklearn
I think this doc will help you.
You have to use :
onnxmltools.convert_lightgbm
and not
convert.convert_sklearn
正如其他答案所提到的:您必须使用:onnxmltools.convert_lightgbm而不是转换。convert_sklearn
也将引起错误,因为您尚未定义initial_types。 inital_types在 docs 所描述的如下:
假设指定的示例:假设指定的示例Scikit-Learn模型将异质列表作为其输入。如果前5个元素是浮子,而最后10个元素是整数,则需要在下面指定初始类型。 [none,5]中的[无]表示这里的批处理大小是未知的。
As the other answer mentions: You have to use : onnxmltools.convert_lightgbm and not convert.convert_sklearn
The error would also be caused since you have not defined the initial_types. The inital_types are in the Docs described as follows:
Example of initial_types: Assume that the specified scikit-learn model takes a heterogeneous list as its input. If the first 5 elements are floats and the last 10 elements are integers, we need to specify initial types as below. The [None] in [None, 5] indicates the batch size here is unknown.