TextReconitionModel failed with CTC-prefix-beam-search

usage: OpenCV 4.5.3-dev

I followed this example: opencv/scene_text_spotting.cpp at master · opencv/opencv · GitHub It is use:

for the detection model: DB_TD500_resnet50.onnx
for the recognition model : crnn_cs.onnx
for the vocabulary: alphabet_94.txt
the decode type is set to: "CTC-prefix-beam-search"

These settings received the following error:

OpenCV(4.5.3-dev) C:\DevTools\opencv\modules\dnn\src\model.cpp:745: error: (-2:Unspecified error)     in function 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl cv::dnn::TextRecognitionModel_Impl::ctcPrefixBeamSearchDecode(const class cv::Mat &)'
>  (expected: 'prediction.size[2] == (int)vocabulary.size() + 1'), where
>     'prediction.size[2]' is 96
> must be equal to
>     '(int)vocabulary.size() + 1' is 95

The complete log output is:

[ INFO:0] global C:\DevTools\opencv\modules\core\src\ocl.cpp (1172) cv::ocl::haveOpenCL Initialize OpenCL runtime...
[ INFO:0] global C:\DevTools\opencv\modules\core\src\ocl.cpp (1178) cv::ocl::haveOpenCL OpenCL: found 1 platforms
[ INFO:0] global C:\DevTools\opencv\modules\core\src\ocl.cpp (970) cv::ocl::OpenCLExecutionContext::Impl::getInitializedExecutionContext OpenCL: initializing thread execution context
[ INFO:0] global C:\DevTools\opencv\modules\core\src\ocl.cpp (980) cv::ocl::OpenCLExecutionContext::Impl::getInitializedExecutionContext OpenCL: creating new execution context...
[ INFO:0] global C:\DevTools\opencv\modules\core\src\ocl.cpp (998) cv::ocl::OpenCLExecutionContext::Impl::getInitializedExecutionContext OpenCL: device=NVIDIA TITAN RTX
[ INFO:0] global C:\DevTools\opencv\modules\dnn\src\onnx\onnx_importer.cpp (513) cv::dnn::dnn4_v20210608::ONNXImporter::populateNet DNN/ONNX: loading ONNX v6 model produced by 'pytorch':1.5. Number of nodes = 368, inputs = 1, outputs = 1
[ INFO:0] global C:\DevTools\opencv\modules\dnn\src\onnx\onnx_importer.cpp (513) cv::dnn::dnn4_v20210608::ONNXImporter::populateNet DNN/ONNX: loading ONNX v6 model produced by 'pytorch':1.5. Number of nodes = 179, inputs = 1, outputs = 1
[ INFO:0] global C:\DevTools\opencv\modules\core\src\parallel\registry_parallel.impl.hpp (96) cv::parallel::ParallelBackendRegistry::ParallelBackendRegistry core(parallel): Enabled backends(3, sorted by priority): ONETBB(1000); TBB(990); OPENMP(980)
[ INFO:0] global C:\DevTools\opencv\modules\core\src\utils\plugin_loader.impl.hpp (67) cv::plugin::impl::DynamicLib::libraryLoad load C:\OpenCV-4.5.3-dev\bin\Debug\opencv_core_parallel_onetbb453_64d.dll => FAILED
[ INFO:0] global C:\DevTools\opencv\modules\core\src\utils\plugin_loader.impl.hpp (67) cv::plugin::impl::DynamicLib::libraryLoad load opencv_core_parallel_onetbb453_64d.dll => FAILED
[ INFO:0] global C:\DevTools\opencv\modules\core\src\utils\plugin_loader.impl.hpp (67) cv::plugin::impl::DynamicLib::libraryLoad load C:\OpenCV-4.5.3-dev\bin\Debug\opencv_core_parallel_tbb453_64d.dll => FAILED
[ INFO:0] global C:\DevTools\opencv\modules\core\src\utils\plugin_loader.impl.hpp (67) cv::plugin::impl::DynamicLib::libraryLoad load opencv_core_parallel_tbb453_64d.dll => FAILED
[ INFO:0] global C:\DevTools\opencv\modules\core\src\utils\plugin_loader.impl.hpp (67) cv::plugin::impl::DynamicLib::libraryLoad load C:\OpenCV-4.5.3-dev\bin\Debug\opencv_core_parallel_openmp453_64d.dll => FAILED
[ INFO:0] global C:\DevTools\opencv\modules\core\src\utils\plugin_loader.impl.hpp (67) cv::plugin::impl::DynamicLib::libraryLoad load opencv_core_parallel_openmp453_64d.dll => FAILED
[ WARN:0] global C:\DevTools\opencv\modules\dnn\src\dnn.cpp (1447) cv::dnn::dnn4_v20210608::Net::Impl::setUpNet DNN module was not built with CUDA backend; switching to CPU
[ WARN:0] global C:\DevTools\opencv\modules\dnn\src\dnn.cpp (1447) cv::dnn::dnn4_v20210608::Net::Impl::setUpNet DNN module was not built with CUDA backend; switching to CPU
OpenCV(4.5.3-dev) Error: Unspecified error (>  (expected: 'prediction.size[2] == (int)vocabulary.size() + 1'), where
>     'prediction.size[2]' is 3946
> must be equal to
>     '(int)vocabulary.size() + 1' is 3945
) in class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl cv::dnn::TextRecognitionModel_Impl::ctcPrefixBeamSearchDecode(const class cv::Mat &), file C:\DevTools\opencv\modules\dnn\src\model.cpp, line 745
OpenCV(4.5.3-dev) C:\DevTools\opencv\modules\dnn\src\model.cpp:745: error: (-2:Unspecified error) in function 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl cv::dnn::TextRecognitionModel_Impl::ctcPrefixBeamSearchDecode(const class cv::Mat &)'
>  (expected: 'prediction.size[2] == (int)vocabulary.size() + 1'), where
>     'prediction.size[2]' is 3946
> must be equal to
>     '(int)vocabulary.size() + 1' is 3945

looks like an off-by-one error (in addition to the N+1 calculation).

perhaps open an issue on the github. there you’ll find the people who understand the example and are able to fix it.