日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

[ShapeInferenceError] Mismatch between number of source and target dimensions. Source=1 Target=0

發(fā)布時間:2024/4/15 编程问答 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 [ShapeInferenceError] Mismatch between number of source and target dimensions. Source=1 Target=0 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Pytorch轉(zhuǎn)ONNX模型正常,但使用onnxruntime加載onnx模型,會輸出錯誤:

onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Exception during loading: /onnxruntime_src/onnxruntime/core/graph/function.cc:420 onnxruntime::FunctionImpl::FunctionImpl(const onnxruntime::Graph&, const NodeIndex&, const onnx::FunctionProto&, const onnxruntime::logging::Logger&) status.IsOK() was false. Resolve subgraph failed:Node (0x2b97890_109) Op (Loop) [TypeInferenceError] Graph attribute inferencing failed: Node:0x2b97890_109 Output:cond [ShapeInferenceError] Mismatch between number of source and target dimensions. Source=1 Target=0

相關(guān)issues:https://github.com/microsoft/onnxruntime/issues/1164

從報(bào)錯的描述,大致可以定位是輸出的維度有問題:于是我詳細(xì)Debug一下模型輸出的'boxes', 'scores'的維度變化:

scores輸出維度是(1,13375,2),對應(yīng)(batch_size,num_anchors,num_class)

boxes輸出維度是(13375,4),沒有batch_size這個維度,這是因?yàn)槲疫M(jìn)行boxes.data.squeeze(0)處理,不小心把batch_size去掉了

于是我修改源代碼,保持'boxes', 'scores'都含有batch_size這個維度,變成

scores輸出維度是(1,13375,2),對應(yīng)(batch_size,num_anchors,num_class)

boxes輸出維度是(1,13375,4),對應(yīng)(batch_size,num_anchors,(x,y,cx,cy))

done,重新生成ONNX模型,并使用onnxruntime加載模型,就沒有錯誤了

結(jié)論:轉(zhuǎn)換ONNX模型時,輸入輸出盡量保留batch_size這個維度,盡管batch_size這個維度經(jīng)常為1

總結(jié)

以上是生活随笔為你收集整理的[ShapeInferenceError] Mismatch between number of source and target dimensions. Source=1 Target=0的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。