Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.
6503 Discussions

Output data of the age-gender-recognition-retail-0013 -model

lawHo
Novice
2,857 Views

Hi!

I try to predict age and gender from a face image with age-gender-recognition-retail-0013 -model but I can't seem to understand the documentation correctly.

 

This is my setup:

 

ageGenderNet = cv2.dnn.readNet("models/age-gender-recognition-retail-0013/FP32/age-gender-recognition-retail-0013.xml",
"models/age-gender-recognition-retail-0013/FP32/age-gender-recognition-retail-0013.bin")
genders = ["female", "male"]
faceBlob = cv2.dnn.blobFromImage(face, 1.0, (227, 227),
(78.4263377603, 87.7689143744, 114.895847746),
swapRB=False)

ageGenderNet.setInput(faceBlob)
aPreds = ageGenderNet.forward()
predict_gender = aPreds[0][1][0][0]
gConfidence = aPreds[0][1][1][0]
gd = genders[int(predict_gender + 0.5)]

predict_age = aPreds[0][0][0][0] * 100
aConfidence = aPreds[0][0][1][0]

 

The gender is predicted correctly,  but the age readings are weird and I think I might be doing something wrong. Looking at a camera for a while I get anything from 1 - 90 for my predicted age. Would appreciate if someone could take a look and tell me if I'm extracting the age prediction and its confidence in a wrong way.

0 Kudos
1 Solution
Peh_Intel
Moderator
2,764 Views

Hi lawHo,


Greetings to you.


For this age-gender-recognition-retail-0013 model, it can output two predictions, gender and age. However, gender prediction is trained via classification (male, female) whereas age prediction is trained via regression (values). Therefore, it is only possible to get the confidence for the gender classification.


You may refer to the following tutorial, OpenCV Age Detection with Deep Learning, which discusses how to perform automatic age detection/prediction using OpenCV, Deep Learning, and Python.


You may refer to the following codes for executing the confidence for gender classification which I modified from the tutorial above (line 58-60).


preds = ageGenderNet.forward('prob')                                                                                                                                       

i = preds[0].argmax()

genderConfidence = preds[0][i][0][0]

print('Confidence =' + str(genderConfidence*100) + ' %')



Regards,

Yu Chern 


View solution in original post

5 Replies
Vladimir_Dudnik
Employee
2,828 Views

It might be helpful to review appropriate Open Model Zoo demo, to see what postprocessing required for the model.

0 Kudos
Peh_Intel
Moderator
2,803 Views

Hi lawHo,


Greetings to you.


First of all, this age-gender-recognition-retail-0013 model, has its own limitation and specification which you may refer to the link below. This model is able to recognize age of people in [18, 75] years old range, it is not applicable for children since their faces were not in the training set. Besides, the input shape for the input image should be in [62, 62].

https://docs.openvinotoolkit.org/2021.2/omz_models_intel_age_gender_recognition_retail_0013_description_age_gender_recognition_retail_0013.html#use_case_and_high_level_description


Based on your coding, I found that your prediction for gender and age are based on the same output layer which means the prediction for the age is actually same as the prediction for the gender. You have to specify the prediction for age and gender to its respective output layer appropriately.


If you have a look in the link attached above, you will find that there are two different output layers mentioned which are “age_conv3” for age and “prob” for gender.


You may refer to this thread that has discussed the same topic before and the solution (coding) is also can be found in the thread.



Regards,

Yu Chern


lawHo
Novice
2,791 Views

Thank you @Peh_Intel for your answer, it pushed me forward. i'm still wondering how to get the confidence for age and gender recognition, any ideas how to do that?

0 Kudos
Peh_Intel
Moderator
2,765 Views

Hi lawHo,


Greetings to you.


For this age-gender-recognition-retail-0013 model, it can output two predictions, gender and age. However, gender prediction is trained via classification (male, female) whereas age prediction is trained via regression (values). Therefore, it is only possible to get the confidence for the gender classification.


You may refer to the following tutorial, OpenCV Age Detection with Deep Learning, which discusses how to perform automatic age detection/prediction using OpenCV, Deep Learning, and Python.


You may refer to the following codes for executing the confidence for gender classification which I modified from the tutorial above (line 58-60).


preds = ageGenderNet.forward('prob')                                                                                                                                       

i = preds[0].argmax()

genderConfidence = preds[0][i][0][0]

print('Confidence =' + str(genderConfidence*100) + ' %')



Regards,

Yu Chern 


Peh_Intel
Moderator
2,734 Views

Hi lawHo,


This thread will no longer be monitored since we have provided a solution. If you need any additional information from Intel, please submit a new question.



Regards,

Yu Chern 


0 Kudos
Reply