9 using namespace InferenceEngine;
14 age_gender_detection::age_gender_detection(
17 int maxBatch,
bool isBatchDynamic,
18 bool doRawOutputMessages
20 :
base_detection(
"age/gender", pathToModel, maxBatch, isBatchDynamic, isAsync, doRawOutputMessages)
55 ageBlob->buffer().as<
float*>()[
idx] * 100,
56 genderBlob->buffer().as<
float*>()[
idx * 2 + 1]
59 LOG(
DEBUG) <<
"element" <<
idx <<
", male prob = " <<
r.maleProb <<
", age = " <<
r.age;
72 CNNNetReader netReader;
76 network = netReader.getNetwork();
80 netReader.ReadWeights( binFileName );
82 InferenceEngine::Core ie;
93 LOG(
DEBUG) <<
"Checking Age/Gender Recognition network inputs";
94 InputsDataMap inputInfo(network.getInputsInfo());
95 if (inputInfo.size() != 1)
96 throw std::logic_error(
"Age/Gender Recognition network should have only one input");
97 InputInfo::Ptr& inputInfoFirst = inputInfo.begin()->second;
98 inputInfoFirst->setPrecision(Precision::U8);
99 input = inputInfo.begin()->first;
101 LOG(
DEBUG) <<
"Checking Age/Gender Recognition network outputs";
102 OutputsDataMap outputInfo(network.getOutputsInfo());
103 if (outputInfo.size() != 2)
104 throw std::logic_error(
"Age/Gender Recognition network should have two output layers");
105 auto it = outputInfo.begin();
107 DataPtr ptrAgeOutput = (
it++)->second;
108 DataPtr ptrGenderOutput = (
it++)->second;
111 throw std::logic_error(
"Age output data pointer is not valid");
112 if (!ptrGenderOutput)
113 throw std::logic_error(
"Gender output data pointer is not valid");
117 auto genderCreatorLayer = ptrGenderOutput->getCreatorLayer().lock();
118 auto ageCreatorLayer = ptrAgeOutput->getCreatorLayer().lock();
120 if (!ageCreatorLayer)
121 throw std::logic_error(
"Age creator layer pointer is not valid");
122 if (!genderCreatorLayer)
123 throw std::logic_error(
"Gender creator layer pointer is not valid");
126 if (genderCreatorLayer->type ==
"Convolution")
127 std::swap(ptrAgeOutput, ptrGenderOutput);
129 if (ptrAgeOutput->getCreatorLayer().lock()->type !=
"Convolution")
130 throw std::logic_error(
"In Age/Gender Recognition network, age layer (" + ageCreatorLayer->name +
131 ") should be a Convolution, but was: " + ageCreatorLayer->type);
133 if (ptrGenderOutput->getCreatorLayer().lock()->type !=
"SoftMax")
134 throw std::logic_error(
"In Age/Gender Recognition network, gender layer (" + genderCreatorLayer->name +
135 ") should be a SoftMax, but was: " + genderCreatorLayer->type);
139 LOG(
DEBUG) <<
"Age layer: " << ageCreatorLayer->name;
140 LOG(
DEBUG) <<
"Gender layer: " << genderCreatorLayer->name;
143 #ifdef OPENVINO_NGRAPH
144 if (
auto ngraphFunction = network.getFunction())
148 for (
const auto&
op : ngraphFunction->get_ops())
153 if ((friendly_name.find(ptrGenderOutput->getName()) != std::string::npos) && (output_type ==
"Convolution"))
155 std::swap(ptrAgeOutput, ptrGenderOutput);
160 bool outputAgeOk =
false;
162 for (
const auto&
op : ngraphFunction->get_ops())
167 if ((friendly_name.find(ptrAgeOutput->getName()) != std::string::npos) && (output_type ==
"Convolution")) {
175 throw std::logic_error(
"In Age/Gender Recognition network, Age layer (" + ptrAgeOutput->getName() +
") should be a Convolution");
178 bool outputGenderOk =
false;
180 for (
const auto&
op : ngraphFunction->get_ops()) {
184 if ((friendly_name.find(ptrGenderOutput->getName()) != std::string::npos) && (output_type ==
"Softmax")) {
185 outputGenderOk =
true;
192 throw std::logic_error(
"In Age/Gender Recognition network, Gender layer (" + ptrGenderOutput->getName() +
") should be a Softmax");
198 LOG(
DEBUG) <<
"Age layer: " << ptrAgeOutput->getName();
199 LOG(
DEBUG) <<
"Gender layer: " << ptrGenderOutput->getName();