Python报错Must provide classlabels_strings or classlabels_int64s but not both.

python从机器学习模型导出onnx报错

这个错误发生在导出onnx后进行调用的时候,而错误发生的原因在于导出的时候没有进行标签定义
比如在通过scikit-learn进行学习后根据官网的数据案例会提供如下的导出方法

from skl2onnx import convert_sklearn
from skl2onnx.common.data_types import FloatTensorType

initial_type = [('float_input', FloatTensorType([1, 4]))]
onx = convert_sklearn(clr, initial_types=initial_type)
with open("logreg_iris.onnx", "wb") as f:
    f.write(onx.SerializeToString())

这在官网案例当中其实是没有什么问题的,但是很多情况下我们输出不是单个标签,可能是多维的,举个例子,注意final_type 的输出类型定义

    # initial_type是模型的输入,维度为1*5.
    initial_type = [('float_input', FloatTensorType([1, 5]))]
	#final_type 是模型的输出,维度为1*112
    final_type = [('label', Int64TensorType([1, 112])),
                  ('output', FloatTensorType([1, 112]))]
	#下面rfc_S是学习后的模型
    onx_S = convert_sklearn(rfc_S, initial_types=initial_type, final_types=final_type, options={'zipmap': False})
    # 将模型导出为onnx格式到根目录下
    with open("rcf_S_Onnx.onnx", "wb") as f:
        f.write(onx_S.SerializeToString())
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值