Onnx运行时错误“ SVC转换器不支持与前n个整数不同的类”是什么意思?

如何解决Onnx运行时错误“ SVC转换器不支持与前n个整数不同的类”是什么意思?

我正在尝试将sklearn SVC模型转换/存储为.onnx文件,并且遇到了我不理解的运行时错误。通过sklearn随机森林分类器和sklearn k-NN分类器,我已经能够有效地使用相同的代码而不会出现错误。我收到一个我不理解的奇怪的onnx运行时错误。感谢您提供有关此错误的任何帮助。

我首先在下面发布了运行文件svm_time.py的输出,然后在下面显示了svm_time.py文件中包含的代码。

谢谢。

df %>%
   mutate(x2 = case_when(a == 3 ~  0.05 + x))
python3 svm_time.py 
'train_model'  4809.58 ms
train score is:  0.8765468473777254
val Accuracy is:  0.7037037037037037
Traceback (most recent call last):
  File "svm_time.py",line 97,in <module>
    main()
  File "svm_time.py",line 91,in main
    onx = convert_sklearn(clf,initial_types=initial_type)
  File "/home/matt/anaconda3/envs/venv/lib/python3.7/site-packages/skl2onnx/convert.py",line 154,in convert_sklearn
    dtype=dtype,options=options)
  File "/home/matt/anaconda3/envs/venv/lib/python3.7/site-packages/skl2onnx/common/_topology.py",line 1054,in convert_topology
    conv(scope,operator,container)
  File "/home/matt/anaconda3/envs/venv/lib/python3.7/site-packages/skl2onnx/common/_registration.py",line 29,in __call__
    return self._fct(*args)
  File "/home/matt/anaconda3/envs/venv/lib/python3.7/site-packages/skl2onnx/operator_converters/support_vector_machines.py",line 221,in convert_sklearn_svm_classifier
    "Classes different from first n integers are not supported "
RuntimeError: Classes different from first n integers are not supported in SVC converter.

解决方法

在我看来,这可能是Onnx和sklearn的兼容性问题。

1)。 https://github.com/onnx/sklearn-onnx/issues/302 2)。 https://github.com/onnx/sklearn-onnx/blob/master/skl2onnx/operator_converters/support_vector_machines.py#L17

基于这两个来源,我更改了代码,以包括OVO决策函数形状而不是OVR,现在,至少在运行svm_time.py文件时,将保存一个.onnx文件。

import numpy as np
import pandas as pd
import plotly.graph_objects as go
import plotly.express as px
import datetime

pd.set_option('display.max_rows',None)

# data sample
nperiods = 200
np.random.seed(123)
df = pd.DataFrame(np.random.randint(-10,12,size=(nperiods,4)),columns=list('ABCD'))
datelist = pd.date_range(datetime.datetime(2020,1,1).strftime('%Y-%m-%d'),periods=nperiods).tolist()
df['dates'] = datelist 
df = df.set_index(['dates'])
df.index = pd.to_datetime(df.index)
df.iloc[0] = 0
df = df.cumsum().reset_index()

# function to set background color for a
# specified variable and a specified level



# plotly setup
fig = px.line(df,x='dates',y=df.columns[1:])
fig.update_xaxes(showgrid=True,gridwidth=1,gridcolor='rgba(0,255,0.1)')
fig.update_yaxes(showgrid=True,0.1)')

def bgLevels(fig,variable,level,mode,fillcolor,layer):
    """
    Set a specified color as background for given
    levels of a specified variable using a shape.
    
    Keyword arguments:
    ==================
    fig -- plotly figure
    variable -- column name in a pandas dataframe
    level -- int or float
    mode -- set threshold above or below
    fillcolor -- any color type that plotly can handle
    layer -- position of shape in plotly fiugre,like "below"
    
    """
    
    if mode == 'above':
        m = df[variable].gt(level)
    
    if mode == 'below':
        m = df[variable].lt(level)
        
    df1 = df[m].groupby((~m).cumsum())['dates'].agg(['first','last'])

    for index,row in df1.iterrows():
        #print(row['first'],row['last'])
        fig.add_shape(type="rect",xref="x",yref="paper",x0=row['first'],y0=0,x1=row['last'],y1=1,line=dict(color="rgba(0,0)",width=3,),fillcolor=fillcolor,layer=layer) 
    return(fig)

fig = bgLevels(fig = fig,variable = 'A',level = 100,mode = 'above',fillcolor = 'rgba(100,100,0.2)',layer = 'below')

fig = bgLevels(fig = fig,variable = 'D',level = -60,mode = 'below',fillcolor = 'rgba(255,layer = 'below')

fig.show()

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 &lt;select id=&quot;xxx&quot;&gt; SELECT di.id, di.name, di.work_type, di.updated... &lt;where&gt; &lt;if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 &lt;property name=&quot;dynamic.classpath&quot; value=&quot;tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams[&#39;font.sans-serif&#39;] = [&#39;SimHei&#39;] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -&gt; systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping(&quot;/hires&quot;) public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate&lt;String
使用vite构建项目报错 C:\Users\ychen\work&gt;npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-