Opencv Can not import BidirectionalLSTM

Hi
from this issue and many similar, I know that OpenCV can not import BidirectionalLSTM when my model is written in Keras and converted to ONNX. but when I write my model in PyTorch and convert it to ONNX OpenCV CAN import BidirectionalLSTM. I just wonder why this is happening. any help would be highly appreciated :slight_smile:

which opencv is it ?
(issue is a year old)

My OpenCV version is 4.5.3. and if you notice OpenCV has just fixed this issue in this commit. but my question is why this is happening because this is definitely not related to which framework I use

and the exact errors are ?
did you find out, what the differences between the models are ?

The error is:

[ERROR:0] global /build/opencv/src/opencv-4.5.3/modules/dnn/src/onnx/onnx_importer.cpp (310) getLayerParams DNN/ONNX/Attribute[activations]: ‘Strings’ (6) are not supported
[ERROR:0] global /build/opencv/src/opencv-4.5.3/modules/dnn/src/onnx/onnx_importer.cpp (313) getLayerParams Attribute[activations].string(0) = ‘Sigmoid’
[ERROR:0] global /build/opencv/src/opencv-4.5.3/modules/dnn/src/onnx/onnx_importer.cpp (313) getLayerParams Attribute[activations].string(1) = ‘Tanh’
[ERROR:0] global /build/opencv/src/opencv-4.5.3/modules/dnn/src/onnx/onnx_importer.cpp (313) getLayerParams Attribute[activations].string(2) = ‘Tanh’
[ERROR:0] global /build/opencv/src/opencv-4.5.3/modules/dnn/src/onnx/onnx_importer.cpp (313) getLayerParams Attribute[activations].string(3) = ‘Sigmoid’
[ERROR:0] global /build/opencv/src/opencv-4.5.3/modules/dnn/src/onnx/onnx_importer.cpp (313) getLayerParams Attribute[activations].string(4) = ‘Tanh’
[ERROR:0] global /build/opencv/src/opencv-4.5.3/modules/dnn/src/onnx/onnx_importer.cpp (313) getLayerParams Attribute[activations].string(5) = ‘Tanh’
[ERROR:0] global /build/opencv/src/opencv-4.5.3/modules/dnn/src/onnx/onnx_importer.cpp (2125) handleNode DNN/ONNX: ERROR during processing node with 8 inputs and 3 outputs: [LSTM]:(bidirectional_4_Y)
terminate called after throwing an instance of ‘cv::Exception’
what(): OpenCV(4.5.3) /build/opencv/src/opencv-4.5.3/modules/dnn/src/onnx/onnx_importer.cpp:2146: error: (-2:Unspecified error) in function ‘handleNode’

Node [LSTM]:(bidirectional_4_Y) parse error: OpenCV(4.5.3) /build/opencv/src/opencv-4.5.3/modules/dnn/src/onnx/onnx_importer.cpp:315: error: (-213:The function/feature is not implemented) DNN/ONNX/Attribute[activations]: ‘Strings’ (6) are not supported in function ‘getLayerParams’

1 Like

so, 4.5.3 release does not have the fix.
what about updating to latest master ?

it shouldnt be so, but it is, unfortunately

No, I can not use the non-stable version.

this is the point I can not understand. because the ONNX specification should be the same ( for a specific opset) regardless of the framework I use. I mean there should be no differences when you convert BidirectionalLSTM written in Keras and when you convert it in Pytorch

hey, yea. unfortunately, opencv devs there dont “implement an onnx opset”, just the most needed parts to support the “model zoo”
and the pytorch workflow is simply better tested, than keras or such

1 Like

That was the answer i was looking for. thank you so much for your answer and your time :))

1 Like