【解决方案】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文件即可解决该问题。


目录
相关文章
|
算法框架/工具
成功解决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
|
4月前
|
Go 索引
internal\model\data_support.go:17:10: cannot use _ as value or type
internal\model\data_support.go:17:10: cannot use _ as value or type
|
5月前
|
TensorFlow 算法框架/工具 Python
【Tensorflow】Found unexpected keys that do not correspond to any Model output: dict_keys([‘model_outp
文章讨论了在使用Tensorflow 2.3时遇到的错误信息:"Found unexpected keys that do not correspond to any Model output: dict_keys(['model_output']). Expected: ['dense']"。这个问题通常发生在模型的输出层命名与model.fit_generator的生成器函数中返回的值的键不匹配时。
60 1
|
API 数据格式
TensorFlow2._:model.summary() Output Shape为multiple解决方法
TensorFlow2._:model.summary() Output Shape为multiple解决方法
298 0
TensorFlow2._:model.summary() Output Shape为multiple解决方法
|
异构计算
解决ValueError: Unsupported ONNX opset version: 16问题
解决ValueError: Unsupported ONNX opset version: 16问题
803 0
|
PyTorch 算法框架/工具
Pytorch报错:AttributeError: ‘version_info‘ object has no attribute ‘__version__‘
Pytorch报错:AttributeError: ‘version_info‘ object has no attribute ‘__version__‘
191 0
|
数据格式
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
230 0
ValueError: This model has not yet been built. Build the model first by calling `build()` or calling
|
机器学习/深度学习 并行计算 PyTorch
成功解决torch.cuda.CudaError: CUDA driver version is insufficient for CUDA runtime version (35) [ WARN:0
成功解决torch.cuda.CudaError: CUDA driver version is insufficient for CUDA runtime version (35) [ WARN:0
成功解决torch.cuda.CudaError: CUDA driver version is insufficient for CUDA runtime version (35) [ WARN:0
|
机器学习/深度学习 计算机视觉
成功解决This module was deprecated in version 0.18 in favor of the model_selection module into which all
成功解决This module was deprecated in version 0.18 in favor of the model_selection module into which all
|
计算机视觉
成功解决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