opencv: Error while loading pytorch model in opencv
While reading the CRNN model from meijieru in OpenCV, I got the following error
import cv2
net = cv2.dnn.readNetFromTorch("crnn.pth")
error: OpenCV(4.2.0) C:\projects\opencv-python\opencv\modules\dnn\src\torch\torch_importer.cpp:1022: error: (-213:The function/feature is not implemented) Unsupported Lua type in function 'cv::dnn::dnn4_v20191202::TorchImporter::readObject'
model link How to fix this error?
System information (version)
- OpenCV = 4.2.0
- Operating System / Platform => Windows 64 Bit
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 33 (26 by maintainers)
amazing news 😉
using the model from meijieru (and resp. preprocessing) i could reproduce results:
imho, we can close this issue 😉
@saraansh1999, I believe that this fix will enable the
crnn
model so nothing will remain for the summer 😃i just tried https://github.com/opencv/opencv/pull/16817 and it can at least read the crnn.onnx correctly (including bidirectional LSTM) 😉
thanks, @dkurt !!
@sunice-nyy please have a look at https://github.com/opencv/opencv/pull/16817 , which will add ConstantOfShape and LSTM import from onnx
torch.load()
loads a state_dict, not a model. (you have to construct the model first, then upload its state_dict) assuming this repo , try:Please read the documentation for readNetFromTorch method: https://docs.opencv.org/master/d6/d0f/group__dnn.html#ga65a1da76cb7d6852bdf7abbd96f19084. It is used for Torch models, not PyTorch. For PyTorch you need to convert it to ONNX and use readNet.