-
-
Notifications
You must be signed in to change notification settings - Fork 56.5k
dnn onnx importer parseGemm issue #22096
Copy link
Copy link
Closed
Labels
Milestone
Description
I tried to import a small onnx model, for logistic_regression, with Gemm operator. And I encountered assertion error as following:
>>> cv2.dnn.readNetFromONNX('logistic_regression.onnx')
[ERROR:0@152.260] global D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\onnx\onnx_importer.cpp (1021) cv::dnn::dnn4_v20220524::ONNXImporter::handleNode DNN/ONNX: ERROR during processing node with 3 inputs and 1 outputs: [Gemm]:(onnx_node!Gemm_0003) from domain='ai.onnx'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cv2.error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\onnx\onnx_importer.cpp:1040: error: (-2:Unspecified error) in function 'cv::dnn::dnn4_v20220524::ONNXImporter::handleNode'
> Node [Gemm@ai.onnx]:(onnx_node!Gemm_0003) parse error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\layers\fully_connected_layer.cpp:92: error: (-215:Assertion failed) !bias || (blobs.size() == 2 && (size_t)numOutput == blobs[1].total()) in function 'cv::dnn::FullyConnectedLayerImpl::FullyConnectedLayerImpl'
After I checked the source code:
opencv/modules/dnn/src/onnx/onnx_importer.cpp
Line 2089 in b19683e
| if (layerParams.has("transB") && !layerParams.get<int>("transB")) { |
I found when Gemm operator has attr transB=0,
if origin Gemm performs A(M,K) * B(K,N), after
opencv/modules/dnn/src/onnx/onnx_importer.cpp
Line 2090 in b19683e
| transpose(weights, weights); |
it becomes A(M,K) * B'(N,K), but shouldn't
ind_num_out still be 0,opencv/modules/dnn/src/onnx/onnx_importer.cpp
Line 2113 in b19683e
| layerParams.set("num_output", layerParams.blobs[0].size[ind_num_out]); |
so
num_output would still be N?
Also, I found if attr transB is not set(I mean missing, which would be treated using default mode), the procedure would not handle such scenario.
Here is my onnx model:
logistic_regression.zip
Reactions are currently unavailable