22// SPDX-License-Identifier: Apache-2.0
33//
44
5+ #include < algorithm>
6+ #include < memory>
57#include < string>
8+ #include < vector>
69
7- #include " openvino/openvino.hpp"
10+ #include < gflags/gflags.h>
11+ #include < openvino/openvino.hpp>
12+
13+ #include < utils/slog.hpp>
814
9- #include " gflags/gflags.h"
10- #include " utils/slog.hpp"
1115#include " detection_base.hpp"
1216
1317struct PersonAttribsDetection : BaseDetection {
@@ -16,7 +20,6 @@ struct PersonAttribsDetection : BaseDetection {
1620 std::string outputNameForBottomColorPoint;
1721 bool hasTopBottomColor;
1822
19-
2023 PersonAttribsDetection () : BaseDetection(FLAGS_m_pa, " Person Attributes Recognition" ), hasTopBottomColor(false ) {}
2124
2225 struct AttributesAndColorPoints {
@@ -37,8 +40,13 @@ struct PersonAttribsDetection : BaseDetection {
3740 image.convertTo (image32f, CV_32F);
3841 image32f = image32f.reshape (1 , image32f.rows * image32f.cols );
3942 clusterCount = std::min (clusterCount, image32f.rows );
40- cv::kmeans (image32f, clusterCount, labels, cv::TermCriteria (cv::TermCriteria::EPS+cv::TermCriteria::MAX_ITER, 10 , 1.0 ),
41- 10 , cv::KMEANS_RANDOM_CENTERS, centers);
43+ cv::kmeans (image32f,
44+ clusterCount,
45+ labels,
46+ cv::TermCriteria (cv::TermCriteria::EPS + cv::TermCriteria::MAX_ITER, 10 , 1.0 ),
47+ 10 ,
48+ cv::KMEANS_RANDOM_CENTERS,
49+ centers);
4250 centers.convertTo (centers, CV_8U);
4351 centers = centers.reshape (3 , clusterCount);
4452 std::vector<int > freq (clusterCount);
@@ -53,12 +61,16 @@ struct PersonAttribsDetection : BaseDetection {
5361 }
5462
5563 AttributesAndColorPoints GetPersonAttributes () {
56- static const char * const attributeStringsFor7Attributes[] = {
57- " is male" , " has_bag" , " has hat" , " has longsleeves" , " has longpants" , " has longhair" , " has coat_jacket"
58- };
59- static const char * const attributeStringsFor8Attributes[] = {
60- " is male" , " has_bag" , " has_backpack" , " has hat" , " has longsleeves" , " has longpants" , " has longhair" , " has coat_jacket"
61- };
64+ static const char * const attributeStringsFor7Attributes[] =
65+ {" is male" , " has_bag" , " has hat" , " has longsleeves" , " has longpants" , " has longhair" , " has coat_jacket" };
66+ static const char * const attributeStringsFor8Attributes[] = {" is male" ,
67+ " has_bag" ,
68+ " has_backpack" ,
69+ " has hat" ,
70+ " has longsleeves" ,
71+ " has longpants" ,
72+ " has longhair" ,
73+ " has coat_jacket" };
6274
6375 ov::Tensor attribsTensor = m_infer_request.get_tensor (outputNameForAttributes);
6476 size_t numOfAttrChannels = attribsTensor.get_shape ()[1 ];
@@ -69,12 +81,12 @@ struct PersonAttribsDetection : BaseDetection {
6981 } else if (numOfAttrChannels == arraySize (attributeStringsFor8Attributes)) {
7082 attributeStrings = attributeStringsFor8Attributes;
7183 } else {
72- throw std::logic_error (" Output size (" + std::to_string (numOfAttrChannels) + " ) of the "
84+ throw std::logic_error (" Output size (" + std::to_string (numOfAttrChannels) +
85+ " ) of the "
7386 " Person Attributes Recognition network is not equal to expected "
74- " number of attributes ("
75- + std::to_string (arraySize (attributeStringsFor7Attributes))
76- + " or "
77- + std::to_string (arraySize (attributeStringsFor7Attributes)) + " )" );
87+ " number of attributes (" +
88+ std::to_string (arraySize (attributeStringsFor7Attributes)) + " or " +
89+ std::to_string (arraySize (attributeStringsFor7Attributes)) + " )" );
7890 }
7991
8092 AttributesAndColorPoints returnValue;
@@ -92,11 +104,13 @@ struct PersonAttribsDetection : BaseDetection {
92104 size_t numOfTCPointChannels = topColorPointTensor.get_shape ()[1 ];
93105 size_t numOfBCPointChannels = bottomColorPointTensor.get_shape ()[1 ];
94106 if (numOfTCPointChannels != 2 ) {
95- throw std::logic_error (" Output size (" + std::to_string (numOfTCPointChannels) + " ) of the "
107+ throw std::logic_error (" Output size (" + std::to_string (numOfTCPointChannels) +
108+ " ) of the "
96109 " Person Attributes Recognition network is not equal to point coordinates(2)" );
97110 }
98111 if (numOfBCPointChannels != 2 ) {
99- throw std::logic_error (" Output size (" + std::to_string (numOfBCPointChannels) + " ) of the "
112+ throw std::logic_error (" Output size (" + std::to_string (numOfBCPointChannels) +
113+ " ) of the "
100114 " Person Attributes Recognition network is not equal to point coordinates (2)" );
101115 }
102116
@@ -118,8 +132,9 @@ struct PersonAttribsDetection : BaseDetection {
118132 }
119133
120134 bool CheckOutputNameExist (const ov::OutputVector& outputs, const std::string name) {
121- if (std::find_if (outputs.begin (), outputs.end (),
122- [&](const ov::Output<ov::Node>& output) {return output.get_any_name () == name; }) == outputs.end ()) {
135+ if (std::find_if (outputs.begin (), outputs.end (), [&](const ov::Output<ov::Node>& output) {
136+ return output.get_any_name () == name;
137+ }) == outputs.end ()) {
123138 return false ;
124139 }
125140 return true ;
@@ -144,19 +159,15 @@ struct PersonAttribsDetection : BaseDetection {
144159 ov::preprocess::PrePostProcessor ppp = ov::preprocess::PrePostProcessor (model);
145160
146161 if (FLAGS_auto_resize) {
147- ppp.input ().tensor ().
148- set_element_type (ov::element::u8 ).
149- set_spatial_dynamic_shape ().
150- set_layout ({ " NHWC" });
151- ppp.input ().preprocess ().
152- convert_element_type (ov::element::f32 ).
153- convert_layout (" NCHW" ).
154- resize (ov::preprocess::ResizeAlgorithm::RESIZE_LINEAR);
162+ ppp.input ().tensor ().set_element_type (ov::element::u8 ).set_spatial_dynamic_shape ().set_layout ({" NHWC" });
163+ ppp.input ()
164+ .preprocess ()
165+ .convert_element_type (ov::element::f32 )
166+ .convert_layout (" NCHW" )
167+ .resize (ov::preprocess::ResizeAlgorithm::RESIZE_LINEAR);
155168 ppp.input ().model ().set_layout (" NCHW" );
156169 } else {
157- ppp.input ().tensor ().
158- set_element_type (ov::element::u8 ).
159- set_layout ({ " NCHW" });
170+ ppp.input ().tensor ().set_element_type (ov::element::u8 ).set_layout ({" NCHW" });
160171 }
161172
162173 model = ppp.build ();
@@ -189,8 +200,9 @@ struct PersonAttribsDetection : BaseDetection {
189200 }
190201 hasTopBottomColor = true ;
191202 } else {
192- throw std::logic_error (" Person Attribs Network expects either a network having one output (person attributes), "
193- " or a network having three outputs (person attributes, top color point, bottom color point)" );
203+ throw std::logic_error (
204+ " Person Attribs Network expects either a network having one output (person attributes), "
205+ " or a network having three outputs (person attributes, top color point, bottom color point)" );
194206 }
195207
196208 m_enabled = true ;
0 commit comments