【解决方案】The opset version of the onnx model is 12, only model with opset_version 10/11 is supported.

简介: 【解决方案】The opset version of the onnx model is 12, only model with opset_version 10/11 is supported.

问题背景

使用Yolov5s模型自带的export.py文件进行模型转换,将.pt文件转成.onnx文件。但模型转换完成后使用hb_mapper checker(地平线天公开物工具链转化工具)时报错:

The opset version of the onnx model is 12, only model with opset_version 10/11 is supported.

意思就是说我在进行onnx模型转化时,opset version 用的是12的版本,但hb_mapper checker工具只支持10/11版本。


解决方案

打开Yolov5s模型下的export.py文件,找到parse_opt()方法。


def parse_opt():
    parser = argparse.ArgumentParser()
    parser.add_argument('--data', type=str, default=ROOT / 'data/coco128.yaml', help='dataset.yaml path')
    parser.add_argument('--weights', nargs='+', type=str, default=ROOT / 'yolov5s.pt', help='model.pt path(s)')
    parser.add_argument('--imgsz', '--img', '--img-size', nargs='+', type=int, default=[640, 640], help='image (h, w)')
    parser.add_argument('--batch-size', type=int, default=1, help='batch size')
    parser.add_argument('--device', default='cpu', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
    parser.add_argument('--half', action='store_true', help='FP16 half-precision export')
    parser.add_argument('--inplace', action='store_true', help='set YOLOv5 Detect() inplace=True')
    parser.add_argument('--train', action='store_true', help='model.train() mode')
    parser.add_argument('--keras', action='store_true', help='TF: use Keras')
    parser.add_argument('--optimize', action='store_true', help='TorchScript: optimize for mobile')
    parser.add_argument('--int8', action='store_true', help='CoreML/TF INT8 quantization')
    parser.add_argument('--dynamic', action='store_true', help='ONNX/TF: dynamic axes')
    parser.add_argument('--simplify', action='store_true', help='ONNX: simplify model')
    parser.add_argument('--opset', type=int, default=12, help='ONNX: opset version')
    parser.add_argument('--verbose', action='store_true', help='TensorRT: verbose log')
    parser.add_argument('--workspace', type=int, default=4, help='TensorRT: workspace size (GB)')
    parser.add_argument('--nms', action='store_true', help='TF: add NMS to model')
    parser.add_argument('--agnostic-nms', action='store_true', help='TF: add agnostic NMS to model')
    parser.add_argument('--topk-per-class', type=int, default=100, help='TF.js NMS: topk per class to keep')
    parser.add_argument('--topk-all', type=int, default=100, help='TF.js NMS: topk for all classes to keep')
    parser.add_argument('--iou-thres', type=float, default=0.45, help='TF.js NMS: IoU threshold')
    parser.add_argument('--conf-thres', type=float, default=0.25, help='TF.js NMS: confidence threshold')
    parser.add_argument('--include',
                        nargs='+',
                        default=['torchscript', 'onnx'],
                        help='torchscript, onnx, openvino, engine, coreml, saved_model, pb, tflite, edgetpu, tfjs')
    opt = parser.parse_args()
    print_args(vars(opt))
    return opt
def main(opt):
    for opt.weights in (opt.weights if isinstance(opt.weights, list) else [opt.weights]):
        run(**vars(opt))
if __name__ == "__main__":
    opt = parse_opt()
    main(opt)

找到parser.add_argument('--opset', type=int, default=12, help='ONNX: opset version')这条语句,将默认值修改为11,如:parser.add_argument('--opset', type=int, default=11, help='ONNX: opset version')。然后重新将.pt转化成.onnx文件即可解决该问题。


目录
相关文章
|
19天前
|
监控 测试技术 持续交付
什么是 Microdelivery Release Model
什么是 Microdelivery Release Model
29 0
|
5天前
|
SQL 数据库
一个很实用的造数工具—Spawner Data Generator
一个很实用的造数工具—Spawner Data Generator
8 0
|
18天前
|
存储 供应链 搜索推荐
Spartacus product variant configuration sample data
Spartacus product variant configuration sample data
19 2
|
算法框架/工具
成功解决INFO: pip is looking at multiple versions of keras-preprocessing to determine which version is c
成功解决INFO: pip is looking at multiple versions of keras-preprocessing to determine which version is c
|
API 数据格式
TensorFlow2._:model.summary() Output Shape为multiple解决方法
TensorFlow2._:model.summary() Output Shape为multiple解决方法
206 0
TensorFlow2._:model.summary() Output Shape为multiple解决方法
|
12月前
|
TensorFlow 算法框架/工具 Python
tensorflow安装错误:Could not find a version that satisfies the requirement tensorflow 解决
tensorflow安装错误:Could not find a version that satisfies the requirement tensorflow 解决
|
数据格式
ValueError: This model has not yet been built. Build the model first by calling `build()` or calling
ValueError: This model has not yet been built. Build the model first by calling `build()` or calling
160 0
ValueError: This model has not yet been built. Build the model first by calling `build()` or calling
【yolov5报错】Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘--yolov5-5.0\models\common.py
【yolov5报错】Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘--yolov5-5.0\models\common.py
1025 0
|
JSON 数据格式
difference between JSON Model and client model
Created by Wang, Jerry on Sep 25, 2015
85 0
difference between JSON Model and client model
|
计算机视觉
成功解决sklearn\cross_validation.py:41: DeprecationWarning: This module was deprecated in version 0.18 i
成功解决sklearn\cross_validation.py:41: DeprecationWarning: This module was deprecated in version 0.18 i