yolov7-tiny轉檔問題請教

嗨,目前嘗試將yolov7-tiny的模型轉當成NEF檔,並燒錄到KL630的開發板上。

以下是我的流程:

1..pt -> .onnx

(使用yolov7官方的export.py)

python export.py --weights yolov7-tiny.pt --grid --end2end --simplify --topk-all 100 --iou-thres 0.65 --conf-thres 0.35 --img-size 640 640 --max-wh 640

2..onnx -> sim.onnx

onnxsim yolov7-tiny.onnx yolov7-tiny_sim.onnx

3. sim.onnx -> sim_convert.onnx

python ONNX_Convertor/optimizer_scripts/onnx2onnx.py yolov7-tiny_sim.onnx -o yolov7-tiny_sim_convert.onnx

"""

INFO:optimizer_scripts:Preprocessing the model...

WARNING:optimizer_scripts:The following operatos are currently not well supported by our toolchain: {'ArgMax'}

(op_type:Concat, name:Concat_312): Inferred shape and existing shape differ in dimension 0: (1) vs (21)

Traceback (most recent call last):

 File "ONNX_Convertor/optimizer_scripts/onnx2onnx.py", line 155, in <module>

  duplicate_shared_weights=args.duplicate_shared_weights)

 File "ONNX_Convertor/optimizer_scripts/onnx2onnx.py", line 46, in onnx2onnx_flow

  m = combo.preprocess(m, disable_fuse_bn, duplicate_shared_weights)

 File "/data/NAS/ComputeServer/ytl0623/ai_training/detection/yolov5/yolov5/ONNX_Convertor/optimizer_scripts/tools/combo.py", line 73, in preprocess

  model_proto = onnx.utils.polish_model(model_proto)

 File "/home/ytl0623/data/anaconda3/envs/yolov5-py3.7/lib/python3.7/site-packages/onnx/utils.py", line 20, in polish_model

  model = onnx.shape_inference.infer_shapes(model)

 File "/home/ytl0623/data/anaconda3/envs/yolov5-py3.7/lib/python3.7/site-packages/onnx/shape_inference.py", line 35, in infer_shapes

  inferred_model_str = C.infer_shapes(model_str, check_type)

RuntimeError: Inferred shape and existing shape differ in dimension 0: (1) vs (21)

"""

想請問以上轉檔流程是否有誤,另外error的原因猜測是有不支援的opearator,我應該如何解決?

以上問題請教,感謝。

Comments

  • Hello,

    看訊息中有提到ArgMax,推測是模型中含有這個不支援的operator所造成

    argmax是基於多個機率取最大值的運算,一般來說我們會放在後處理中再執行,所以要請你將onnx模型的最末端做調整,我們自己內部會是到Sigmoid的地方做結尾,剩餘的移到後處理來執行

    有關yolov7的相關修改,也可以參考我們提供的修改說明

    https://www.kneron.com/tw/support/developers/?folder=Documentation%20center/&download=1904


  • Hi, 感謝回覆,想請問一下

    1. -0.5~0.5 是因為要轉換成 int8 的原因嗎?

    2. 請問投影片最後一張是指 models/yolo.py 這個檔案嗎? 另外,是要把原本的 forward function 更改成 modify版本嗎? (但我看行數對不太起來)


    以上問題請教,感謝。

  • Hello,

    有關您的問題如下

    1. 是的,因為是耐能的NPU是INT8,建議運算的數值介於 -2^n ~ 2^n這個範圍才不會犧牲精確度,耐能本身都是採用-0.5~0.5這個範圍
    2. 因為投影片是依據過去修改的經驗整理出來的,所以行數可能與現在最新的版本有所差異。但最後一頁的概念就是要將訓練好的模型在輸出成onnx時,移除掉推論時不需要用到的設定,可以參考modified的版本來修改。
The discussion has been closed due to inactivity. To continue with the topic, please feel free to post a new discussion.