hi, all.
I made a dnn example that recognizes Korean character.
The deep learning model used in this program was trained using the source code released by IBM.
The trained model was saved into a .pb file using the code like this:
output_graph_def = graph_util.convert_variables_to_constants(
sess, sess.graph_def, [output_node_name])
with gfile.FastGFile('./korean_recognition.pb', 'wb') as f:
f.write(output_graph_def.SerializeToString())
The deep learning network’s input is a 64x64 grayscale image.
So, in the dnn example program, I created a blob using the below, where img is a 400x400 grayscale image.
img = np.zeros((400, 400), dtype=np.uint8)
# draw character using mouse...
blob = cv2.dnn.blobFromImage(img, 1, (64, 64))
net.setInput(blob)
out = net.forward() # out.shape=(1, 256)
It was confirmed that this code works well in OpenCV 4.2.
However, it does not work in the latest version of OpenCV.
Upon investigation, no error occurs until opencv-python==4.5.2.54, and the following error occurs after opencv-python==4.5.3.36.
C:\coding\tf>python dnnkorean.py
(1, 1, 64, 64) <class 'numpy.ndarray'> float32
[ERROR:0@2.393] global D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\net_impl.cpp (1171) cv::dnn::dnn4_v20220524::Net::Impl:: getLayerShapesRecursively OPENCV/DNN: [Convolution]:(Conv2D): getMemoryShapes() throws exception. inputs=1 outputs=0/1 blobs=1
[ERROR:0@2.395] global D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\net_impl.cpp (1174) cv::dnn::dnn4_v20220524::Net::Impl:: getLayerShapesRecursively input[0] = [ 1 64 64 1 ]
[ERROR:0@2.397] global D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\net_impl.cpp (1182) cv::dnn::dnn4_v20220524::Net::Impl:: getLayerShapesRecursively blobs[0] = CV_32FC1 [ 32 1 5 5 ]
[ERROR:0@2.399] global D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\net_impl.cpp (1184) cv::dnn::dnn4_v20220524::Net::Impl:: getLayerShapesRecursively Exception message: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\layers\convolution_layer.cpp:406: error: (-215:Assertion failed) ngroups > 0 && inpCn % ngroups == 0 && outCn % ngroups == 0 in function 'cv::dnn::ConvolutionLayerImpl::getMemoryShapes'
Traceback (most recent call last):
File "dnnkorean.py", line 64, in <module>
out = net.forward() # out.shape=(1, 256)
cv2.error: OpenCV(4.6.0) D:\a\opencv-python\opencv-python\opencv\modules\dnn\src\layers\convolution_layer.cpp:406: error: (-215:Assertion failed) ngroups > 0 && inpCn % ngroups == 0 && outCn % ngroups == 0 in function 'cv::dnn::ConvolutionLayerImpl::getMemoryShapes'
Can you figure out the cause?