14 age_gender_detection::age_gender_detection(
15 const std::string &pathToModel,
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]
72 CNNNetReader netReader;
75 netReader.ReadNetwork( pathToModel );
76 network = netReader.getNetwork();
79 std::string binFileName =
remove_ext( pathToModel ) +
".bin";
80 netReader.ReadWeights( binFileName );
82 InferenceEngine::Core ie;
84 network = ie.ReadNetwork(pathToModel);
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())
150 std::string friendly_name =
op->get_friendly_name();
151 std::string output_type =
op->get_type_name();
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())
164 std::string friendly_name =
op->get_friendly_name();
165 std::string output_type =
op->get_type_name();
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()) {
181 std::string friendly_name =
op->get_friendly_name();
182 std::string output_type =
op->get_type_name();
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();
InferenceEngine::InferRequest::Ptr _request
std::string remove_ext(const std::string &filepath)
InferenceEngine::ExecutableNetwork net
LOG(INFO)<< "Log message to default logger"
void submit_request() override
NLOHMANN_BASIC_JSON_TPL_DECLARATION void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL &j1, nlohmann::NLOHMANN_BASIC_JSON_TPL &j2) noexcept(//NOLINT(readability-inconsistent-declaration-parameter-name) is_nothrow_move_constructible< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value &&//NOLINT(misc-redundant-expression) is_nothrow_move_assignable< nlohmann::NLOHMANN_BASIC_JSON_TPL >::value)
exchanges the values of two JSON objects
virtual void submit_request()
void enqueue(const cv::Mat &face)
Result operator[](int idx) const
const bool doRawOutputMessages
InferenceEngine::CNNNetwork read_network() override
std::array< float3, 4 > face