# Opencv Can not import BidirectionalLSTM

**URL:** <https://forum.opencv.org/t/opencv-can-not-import-bidirectionallstm/5396>\
**Category:** C++\
**Tags:** dnn\
**Created:** [September 29, 2021, 7:19am UTC](https://forum.opencv.org/t/opencv-can-not-import-bidirectionallstm/5396 "2021-09-29T07:19:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![moghaddam](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@moghaddam](https://forum.opencv.org/u/moghaddam)\
**Post date:** [September 29, 2021, 7:19am UTC](https://forum.opencv.org/t/opencv-can-not-import-bidirectionallstm/5396/1 "2021-09-29T07:19:39Z")

</div>

Hi  
from this [issue](https://github.com/opencv/opencv/issues/18390) 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 🙂

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [September 29, 2021, 7:28am UTC](https://forum.opencv.org/t/opencv-can-not-import-bidirectionallstm/5396/2 "2021-09-29T07:28:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![moghaddam](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@moghaddam](https://forum.opencv.org/u/moghaddam)\
**Post date:** [September 29, 2021, 7:36am UTC](https://forum.opencv.org/t/opencv-can-not-import-bidirectionallstm/5396/3 "2021-09-29T07:36:12Z")

</div>

My OpenCV version is 4.5.3. and if you notice OpenCV has just fixed this issue in this [commit](https://github.com/opencv/opencv/pull/20506). but my question is why this is happening because this is definitely not related to which framework I use

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [September 29, 2021, 7:37am UTC](https://forum.opencv.org/t/opencv-can-not-import-bidirectionallstm/5396/4 "2021-09-29T07:37:42Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![moghaddam](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@moghaddam](https://forum.opencv.org/u/moghaddam)\
**Post date:** [September 29, 2021, 7:39am UTC](https://forum.opencv.org/t/opencv-can-not-import-bidirectionallstm/5396/5 "2021-09-29T07:39:22Z")

</div>

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’

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [September 29, 2021, 8:03am UTC](https://forum.opencv.org/t/opencv-can-not-import-bidirectionallstm/5396/6 "2021-09-29T08:03:01Z")

</div>

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

> [@moghaddam](#):
>
> this is definitely not related to which framework I use

it shouldnt be so, but it is, unfortunately

---

<div class="post-metadata">

**Author:** ![moghaddam](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@moghaddam](https://forum.opencv.org/u/moghaddam)\
**Post date:** [September 29, 2021, 8:15am UTC](https://forum.opencv.org/t/opencv-can-not-import-bidirectionallstm/5396/7 "2021-09-29T08:15:46Z")

</div>

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

> [@berak](#):
>
> it is, unfortunately

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

---

<div class="post-metadata">

**Author:** ![berak](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@berak](https://forum.opencv.org/u/berak)\
**Post date:** [September 29, 2021, 8:24am UTC](https://forum.opencv.org/t/opencv-can-not-import-bidirectionallstm/5396/8 "2021-09-29T08:24:34Z")

</div>

> [@moghaddam](#):
>
> the ONNX specification should be the same

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

---

<div class="post-metadata">

**Author:** ![moghaddam](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@moghaddam](https://forum.opencv.org/u/moghaddam)\
**Post date:** [September 29, 2021, 8:27am UTC](https://forum.opencv.org/t/opencv-can-not-import-bidirectionallstm/5396/9 "2021-09-29T08:27:30Z")

</div>

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