Search code examples
pythonopencvdeep-learningcaffeface-detection

OpenCV deep learning face detection assertion error in function 'cv::dnn::ConvolutionLayerImpl::getMemoryShapes'


I followed tutorial to implement face detection from image with OpenCV and deep learning SSD framework.

modelFile = "./ssd/res10_300x300_ssd_iter_140000.caffemodel"
configFile = "./ssd/deploy.prototxt"
net = cv2.dnn.readNetFromCaffe(configFile, modelFile)
image = cv2.imread("face.jpg")
(h, w) = image.shape[:2]
blob = cv2.dnn.blobFromImage(cv2.resize(image, (300, 300)), 1.0, (300, 300), (104.0, 177.0, 123.0))
net.setInput(blob)
detections = net.forward()

but detections = net.forward() returns error:

error: OpenCV(4.0.0) C:\projects\opencv-python\opencv\modules\dnn\src\layers\convolution_layer.cpp:236: error: (-215:Assertion failed) blobs.size() != 0 in function 'cv::dnn::ConvolutionLayerImpl::getMemoryShapes'

Still looking for more information, but have no idea if it's mistake in code or bug in library... Anyone knows what could cause problem? Any help would be greatly appreciated.


Solution

  • I can't reproduce your problem using both OpenCV 3.4.2 and OpenCV 4.0.0.

    Here's what I get:

    enter image description here

    P.S. I download res10_300x300_ssd_iter_140000.caffemodel from https://raw.githubusercontent.com/opencv/opencv_3rdparty/dnn_samples_face_detector_20170830/res10_300x300_ssd_iter_140000.caffemodel and deploy.prototxt from https://github.com/opencv/opencv/raw/3.4.0/samples/dnn/face_detector/deploy.prototxt.