Hi OpenCV network, I am trying to develop a small face and gender detection using pre-trained tf and intel respectively models. I have no problems with the face part but my problems come with the gender detection. I post here some code:
// Models for face detection (tf)
const std::string faceProto = "../Models/opencv_face_detector.pbtxt";
const std::string faceModel = "../Models/opencv_face_detector_uint8.pb";
// Models for gender detection (intel)
std::string openvino_age_gender_network = "../Models/age-gender-recognition-retail-0013.xml";
std::string openvino_age_gender_model = "../Models/age-gender-recognition-retail-0013.bin";
m_faceNet = cv::dnn::readNet(faceModel, faceProto);
m_faceNet.setPreferableBackend(cv::dnn::DNN_BACKEND_OPENCV);
m_faceNet.setPreferableTarget(cv::dnn::DNN_TARGET_CPU);
m_genderNet = cv::dnn::readNet(openvino_age_gender_network, openvino_age_gender_model);
m_genderNet.setPreferableBackend(cv::dnn::DNN_BACKEND_INFERENCE_ENGINE);
m_genderNet.setPreferableTarget(cv::dnn::DNN_TARGET_CPU);
Every time I retrieve a frame from the camera, i perform the face detection, then i select the roi on the detected face area and apply the gender detection model on that area
// getFaceBox perform face detection using the m_faceNet model on the camera "frame" with a thres of 0.7
std::tie(frameFace, bboxes) = getFaceBox(m_faceNet, frame, 0.7);
frame = frameFace;
if(bboxes.size() == 0)
{
return -1;
}
// Select the face roi
Mat face;
Rect rec(bboxes[0][0] - padding, bboxes[0][1] - padding, bboxes[0][2] - bboxes[0][0] + 2 * padding, bboxes[0][3] - bboxes[0][1] + 2 * padding);
if(rec.x >= 0 && rec.y >= 0 && rec.width + rec.x < frame.cols && rec.height + rec.y < frame.rows)
face = frame(rec);
else
return -1;
Mat blob;
blob = cv::dnn::blobFromImage(face, 1.0, cv::Size(62, 62), CV_8U);
m_genderNet.setInput(blob);
vector<float> genderPreds = m_genderNet.forward("age_conv3"); <--- This call gives runtime error
...more code...
The m_genderNet.forward() gives the following runtime error when it tries to detect the gender:
OpenCV(4.1.1) Error: Assertion failed (d == 2 && (sizes[0] == 1 || sizes[1] == 1 || sizes[0]*sizes[1] == 0)) in cv::_OutputArray::create, file C:\OpenCV4\opencv-4.1.1\modules\core\src\matrix_wrap.cpp, line 1365
I would have a help to solve it please I am not expert in deep learning
Thanx in advance to all