15 age_gender_detection::age_gender_detection(
18 int maxBatch,
bool isBatchDynamic,
19 bool doRawOutputMessages
21 :
base_detection(
"age/gender", pathToModel, maxBatch, isBatchDynamic, isAsync, doRawOutputMessages)
56 ageBlob->buffer().as<
float*>()[idx] * 100,
57 genderBlob->buffer().as<
float*>()[idx * 2 + 1]
70 CNNNetReader netReader;
71 netReader.ReadNetwork(pathToModel);
72 netReader.getNetwork().setBatchSize(
maxBatch);
76 netReader.ReadWeights( binFileName );
80 LOG(
DEBUG) <<
"Checking Age/Gender Recognition network inputs";
81 InputsDataMap inputInfo(netReader.getNetwork().getInputsInfo());
82 if (inputInfo.size() != 1)
83 throw std::logic_error(
"Age/Gender Recognition network should have only one input");
84 InputInfo::Ptr& inputInfoFirst = inputInfo.begin()->second;
85 inputInfoFirst->setPrecision(Precision::U8);
86 input = inputInfo.begin()->first;
88 LOG(
DEBUG) <<
"Checking Age/Gender Recognition network outputs";
89 OutputsDataMap outputInfo(netReader.getNetwork().getOutputsInfo());
90 if (outputInfo.size() != 2)
91 throw std::logic_error(
"Age/Gender Recognition network should have two output layers");
92 auto it = outputInfo.begin();
94 DataPtr ptrAgeOutput = (
it++)->second;
95 DataPtr ptrGenderOutput = (
it++)->second;
98 throw std::logic_error(
"Age output data pointer is not valid");
100 throw std::logic_error(
"Gender output data pointer is not valid");
102 auto genderCreatorLayer = ptrGenderOutput->getCreatorLayer().lock();
103 auto ageCreatorLayer = ptrAgeOutput->getCreatorLayer().lock();
105 if (!ageCreatorLayer)
106 throw std::logic_error(
"Age creator layer pointer is not valid");
107 if (!genderCreatorLayer)
108 throw std::logic_error(
"Gender creator layer pointer is not valid");
111 if (genderCreatorLayer->type ==
"Convolution")
112 std::swap(ptrAgeOutput, ptrGenderOutput);
114 if (ptrAgeOutput->getCreatorLayer().lock()->type !=
"Convolution")
115 throw std::logic_error(
"In Age/Gender Recognition network, age layer (" + ageCreatorLayer->name +
116 ") should be a Convolution, but was: " + ageCreatorLayer->type);
118 if (ptrGenderOutput->getCreatorLayer().lock()->type !=
"SoftMax")
119 throw std::logic_error(
"In Age/Gender Recognition network, gender layer (" + genderCreatorLayer->name +
120 ") should be a SoftMax, but was: " + genderCreatorLayer->type);
123 LOG(
DEBUG) <<
"Age layer: " << ageCreatorLayer->name;
124 LOG(
DEBUG) <<
"Gender layer: " << genderCreatorLayer->name;
131 return netReader.getNetwork();
InferenceEngine::InferRequest::Ptr _request
std::string remove_ext(const std::string &filepath)
InferenceEngine::ExecutableNetwork net
LOG(INFO)<< "Log message to default logger"
GLsizei const GLchar *const * string
void submit_request() override
virtual void submit_request()
void swap(nlohmann::json &j1, nlohmann::json &j2) noexcept(is_nothrow_move_constructible< nlohmann::json >::value andis_nothrow_move_assignable< nlohmann::json >::value)
exchanges the values of two JSON objects
void enqueue(const cv::Mat &face)
GLenum GLenum GLenum input
const bool doRawOutputMessages
InferenceEngine::CNNNetwork read_network() override
Result operator[](int idx) const
GLenum GLuint GLint GLenum face