运行PPE检测仓库代码遇OpenVino报错:__cinit__()意外参数'weights'
问题
首次使用Python运行仓库【PPE-detector-Tiny-YOLOv3-Raspberry-PI-and-NCS2】中的PPE_Detector_Pc.py文件时触发报错,报错信息如下:
PS D:\repository\PPE-detector-Tiny-YOLOv3-Rasp.erry-PI-and-NCS2> py PPE_Detector_Pc.py loading the model... loading plugin on Intel NCS2... Traceback (most recent call last): File "PPE_Detector_Pc.py", line 406, in <module> sys.exit(main_IE_infer() or 0) File "PPE_Detector_Pc.py", line 201, in main_IE_infer net = IENetwork(model=path_to_xml_file, weights=path_to_bin_file) File "ie_api.pyx", line 1598, in openvino.inference_engine.ie_api.IENetwork.__cinit__ TypeError: __cinit__() got an unexpected keyword argument 'weights'
对应的报错代码片段:
path_to_xml_file = "tiny_yolo_IR_500000_FP32.xml" #<--- MYRIAD path_to_bin_file = os.path.splitext(path_to_xml_file)[0] + ".bin" time.sleep(1) print("loading plugin on Intel NCS2...") plugin = IECore() net = IENetwork(model=path_to_xml_file, weights=path_to_bin_file) input_blob = next(iter(net.inputs)) exec_net = plugin.load(network=net)
已将tiny_yolo_IR_500000_FP32.xml和tiny_yolo_IR_500000_FP32.bin置于代码同目录,且已将旧版IEPlugin替换为新版OpenVino支持的IECore,但报错仍存在,需排查遗漏步骤。
解决方案
1. 修正模型加载代码
报错核心原因是新版OpenVINO中IENetwork的初始化接口已变更,旧代码使用的weights参数不再被支持。需将模型加载方式改为通过IECore实例的read_network方法实现:
# 移除原有的IENetwork初始化代码 # net = IENetwork(model=path_to_xml_file, weights=path_to_bin_file) # 替换为以下代码 net = plugin.read_network(model=path_to_xml_file, weights=path_to_bin_file)
2. 确认OpenVINO版本兼容性
IECore及read_network方法从OpenVINO 2020.1版本开始成为标准接口,若你安装的版本早于该版本,建议升级至兼容的稳定版本,避免因API差异导致的问题。
3. 验证模型文件路径有效性
虽然已将模型文件放在同目录,仍可通过打印绝对路径确认文件是否存在:
import os print(f"XML文件绝对路径:{os.path.abspath(path_to_xml_file)}") print(f"BIN文件绝对路径:{os.path.abspath(path_to_bin_file)}")
检查输出路径是否指向真实存在的文件,排除文件名大小写错误、拼写错误等问题。
内容的提问来源于stack exchange,提问作者Ary Maulana
相关产品推荐
相关产品推荐

