2
2
// SPDX-License-Identifier: Apache-2.0
3
3
//
4
4
5
+ #include < algorithm>
6
+ #include < memory>
5
7
#include < string>
8
+ #include < vector>
6
9
7
- #include " openvino/openvino.hpp"
10
+ #include < gflags/gflags.h>
11
+ #include < openvino/openvino.hpp>
12
+
13
+ #include < utils/slog.hpp>
8
14
9
- #include " gflags/gflags.h"
10
- #include " utils/slog.hpp"
11
15
#include " detection_base.hpp"
12
16
13
17
struct PersonAttribsDetection : BaseDetection {
@@ -16,7 +20,6 @@ struct PersonAttribsDetection : BaseDetection {
16
20
std::string outputNameForBottomColorPoint;
17
21
bool hasTopBottomColor;
18
22
19
-
20
23
PersonAttribsDetection () : BaseDetection(FLAGS_m_pa, " Person Attributes Recognition" ), hasTopBottomColor(false ) {}
21
24
22
25
struct AttributesAndColorPoints {
@@ -37,8 +40,13 @@ struct PersonAttribsDetection : BaseDetection {
37
40
image.convertTo (image32f, CV_32F);
38
41
image32f = image32f.reshape (1 , image32f.rows * image32f.cols );
39
42
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);
42
50
centers.convertTo (centers, CV_8U);
43
51
centers = centers.reshape (3 , clusterCount);
44
52
std::vector<int > freq (clusterCount);
@@ -53,12 +61,16 @@ struct PersonAttribsDetection : BaseDetection {
53
61
}
54
62
55
63
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" };
62
74
63
75
ov::Tensor attribsTensor = m_infer_request.get_tensor (outputNameForAttributes);
64
76
size_t numOfAttrChannels = attribsTensor.get_shape ()[1 ];
@@ -69,12 +81,12 @@ struct PersonAttribsDetection : BaseDetection {
69
81
} else if (numOfAttrChannels == arraySize (attributeStringsFor8Attributes)) {
70
82
attributeStrings = attributeStringsFor8Attributes;
71
83
} 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 "
73
86
" 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)) + " )" );
78
90
}
79
91
80
92
AttributesAndColorPoints returnValue;
@@ -92,11 +104,13 @@ struct PersonAttribsDetection : BaseDetection {
92
104
size_t numOfTCPointChannels = topColorPointTensor.get_shape ()[1 ];
93
105
size_t numOfBCPointChannels = bottomColorPointTensor.get_shape ()[1 ];
94
106
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 "
96
109
" Person Attributes Recognition network is not equal to point coordinates(2)" );
97
110
}
98
111
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 "
100
114
" Person Attributes Recognition network is not equal to point coordinates (2)" );
101
115
}
102
116
@@ -118,8 +132,9 @@ struct PersonAttribsDetection : BaseDetection {
118
132
}
119
133
120
134
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 ()) {
123
138
return false ;
124
139
}
125
140
return true ;
@@ -144,19 +159,15 @@ struct PersonAttribsDetection : BaseDetection {
144
159
ov::preprocess::PrePostProcessor ppp = ov::preprocess::PrePostProcessor (model);
145
160
146
161
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);
155
168
ppp.input ().model ().set_layout (" NCHW" );
156
169
} 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" });
160
171
}
161
172
162
173
model = ppp.build ();
@@ -189,8 +200,9 @@ struct PersonAttribsDetection : BaseDetection {
189
200
}
190
201
hasTopBottomColor = true ;
191
202
} 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)" );
194
206
}
195
207
196
208
m_enabled = true ;
0 commit comments