rockchip-linux / rknpu

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Load .onnx yolov5s model got error KeyError: '378'

shaojun opened this issue · comments

我操作的步骤完全参考于:
https://github.com/rockchip-linux/rknn-toolkit/tree/master/examples/onnx/yolov5

  1. 创建conda env with python3.7
    activateenv, 同时安装python dependencies by pip3 install -r requirements.txt.

  2. clone yolov5 并依RKNN文档DEMO时的版本check out到此commit id上:

    使用yolov5官方仓库导出模型,链接:https://github.com/ultralytics/yolov5。该demo创建时yolov5的最新节点的commit id为:c5360f6e7009eb4d05f14d1cc9dae0963e949213
    并在私有数据集上训练了模型,通过detect.py一切正常。

  3. 安装_onnx==1.6.0_ (原因是rknn toolkit中用的是此版本的_onnx_), 并执行了export.pt转至.onnx.

    pip3 list |grep onnx
    onnx                    1.6.0
    

    虽然最后_.onnx_生成了。但同时export过程中可以看到有个failure

    PyTorch: starting from runs/train/exp/weights/last.pt (14.5 MB)

    TorchScript: starting export with torch 1.11.0+cu102...
    ...
    ...
    ONNX: starting export with onnx 1.6.0...
    ...
    ONNX: export failure: Your model ir_version is higher than the checker's.
    Torch version 1.11.0+cu102 has not been tested with coremltools. You may run into unexpected errors. Torch 1.10.2 is the most recent version that has been tested.

    CoreML: starting export with coremltools 5.2.0...
    ...
    ...

    不管它,仍将生成的.onnx拷贝至example/onnx/yolov5/下.

  4. 换到rknn toolkit的conda env:

    执行python3 test.py时,得到以下错误:

    W Call onnx.optimizer.optimize fail, skip optimize
    W Please confirm that your onnx opset_version <= 11 (current opset_verison = 12)!!!
    E Catch exception when loading onnx model: elenet_yolov5s.onnx!
    E Traceback (most recent call last):
    E File "rknn/base/RKNNlib/RK_nn.py", line 141, in rknn.base.RKNNlib.RK_nn.RKnn.load_onnx
    E File "rknn/base/RKNNlib/app/importer/import_onnx.py", line 118, in rknn.base.RKNNlib.app.importer.import_onnx.Importonnx.run
    E File "rknn/base/RKNNlib/converter/convert_onnx.py", line 111, in rknn.base.RKNNlib.converter.convert_onnx.convert_onnx.init
    E File "rknn/base/RKNNlib/converter/convert_onnx.py", line 1059, in rknn.base.RKNNlib.converter.convert_onnx.convert_onnx._build_subgraph
    E File "rknn/base/RKNNlib/converter/onnx_util.py", line 366, in rknn.base.RKNNlib.converter.onnx_util.onnx_subgraph.build_subgraph
    E KeyError: '378'
    E Please feedback the detailed log file <log_feedback_to_the_rknn_toolkit_dev_team.log> to the RKNN Toolkit development team.
    E You can also check github issues: https://github.com/rockchip-linux/rknn-toolkit/issues
    Load yolov5 failed!

  5. 尝试在export yolov4时使用最新的onnx, 即版本1.11.0, 则export无错:

    ONNX: starting export with onnx 1.11.0...
    /home/shao/yolov5/models/yolo.py:58: TracerWarning: Converting a tensor to a Python boolean might cause the trace to be incorrect. We can't record the data flow of Python values, so this value will be treated as a constant in the future. This means that the trace might not generalize to other inputs!
    if self.grid[i].shape[2:4] != x[i].shape[2:4] or self.onnx_dynamic:
    ONNX: export success, saved as runs/train/exp/weights/last.onnx (28.4 MB)
    ONNX: run --dynamic ONNX model inference with: 'python detect.py --weights runs/train/exp/weights/last.onnx'
    Torch version 1.11.0+cu102 has not been tested with coremltools. You may run into unexpected errors. Torch 1.10.2 is the most recent version that has been tested.
    ...
    ...

    但在rknn中执行 python3 test.py, 同样的错误。

Questions:

  1. 以上错误如何避免呢?
  2. 在yolov4中,需要使用什么版本的onnx来做export呢?1.6.0 or 1.11.0?