1616namespace fastdeploy {
1717namespace vision {
1818
19- void ClassifyResult::Clear () {
19+ void ClassifyResult::Free () {
2020 std::vector<int32_t >().swap (label_ids);
2121 std::vector<float >().swap (scores);
2222}
2323
24+ void ClassifyResult::Clear () {
25+ label_ids.clear ();
26+ scores.clear ();
27+ }
28+
2429std::string ClassifyResult::Str () {
2530 std::string out;
2631 out = " ClassifyResult(\n label_ids: " ;
@@ -47,11 +52,16 @@ void Mask::Reserve(int size) { data.reserve(size); }
4752
4853void Mask::Resize (int size) { data.resize (size); }
4954
50- void Mask::Clear () {
55+ void Mask::Free () {
5156 std::vector<uint8_t >().swap (data);
5257 std::vector<int64_t >().swap (shape);
5358}
5459
60+ void Mask::Clear () {
61+ data.clear ();
62+ shape.clear ();
63+ }
64+
5565std::string Mask::Str () {
5666 std::string out = " Mask(" ;
5767 size_t ndim = shape.size ();
@@ -94,26 +104,38 @@ DetectionResult& DetectionResult::operator=(DetectionResult&& other) {
94104 return *this ;
95105}
96106
97- void DetectionResult::Clear () {
107+ void DetectionResult::Free () {
98108 std::vector<std::array<float , 4 >>().swap (boxes);
99109 std::vector<float >().swap (scores);
100110 std::vector<int32_t >().swap (label_ids);
101111 std::vector<Mask>().swap (masks);
102112 contain_masks = false ;
103113}
104114
115+ void DetectionResult::Clear () {
116+ boxes.clear ();
117+ scores.clear ();
118+ label_ids.clear ();
119+ masks.clear ();
120+ contain_masks = false ;
121+ }
122+
105123void DetectionResult::Reserve (int size) {
106124 boxes.reserve (size);
107125 scores.reserve (size);
108126 label_ids.reserve (size);
109- masks.reserve (size);
127+ if (contain_masks) {
128+ masks.reserve (size);
129+ }
110130}
111131
112132void DetectionResult::Resize (int size) {
113133 boxes.resize (size);
114134 scores.resize (size);
115135 label_ids.resize (size);
116- masks.resize (size);
136+ if (contain_masks) {
137+ masks.resize (size);
138+ }
117139}
118140
119141std::string DetectionResult::Str () {
@@ -139,12 +161,18 @@ std::string DetectionResult::Str() {
139161 return out;
140162}
141163
142- void KeyPointDetectionResult::Clear () {
164+ void KeyPointDetectionResult::Free () {
143165 std::vector<std::array<float , 2 >>().swap (keypoints);
144166 std::vector<float >().swap (scores);
145167 num_joints = -1 ;
146168}
147169
170+ void KeyPointDetectionResult::Clear () {
171+ keypoints.clear ();
172+ scores.clear ();
173+ num_joints = -1 ;
174+ }
175+
148176void KeyPointDetectionResult::Reserve (int size) { keypoints.reserve (size); }
149177
150178void KeyPointDetectionResult::Resize (int size) { keypoints.resize (size); }
@@ -155,8 +183,8 @@ std::string KeyPointDetectionResult::Str() {
155183 out = " KeyPointDetectionResult: [x, y, conf]\n " ;
156184 for (size_t i = 0 ; i < keypoints.size (); ++i) {
157185 out = out + std::to_string (keypoints[i][0 ]) + " ," +
158- std::to_string (keypoints[i][1 ]) + " , " +
159- std::to_string (scores[i]) + " \n " ;
186+ std::to_string (keypoints[i][1 ]) + " , " + std::to_string (scores[i]) +
187+ " \n " ;
160188 }
161189 out += " num_joints:" + std::to_string (num_joints) + " \n " ;
162190 return out;
@@ -170,22 +198,22 @@ void OCRResult::Clear() {
170198 cls_labels.clear ();
171199}
172200
173- void MOTResult::Clear (){
201+ void MOTResult::Clear () {
174202 boxes.clear ();
175203 ids.clear ();
176204 scores.clear ();
177205 class_ids.clear ();
178206}
179207
180- std::string MOTResult::Str (){
208+ std::string MOTResult::Str () {
181209 std::string out;
182- out = " MOTResult:\n all boxes counts: " + std::to_string (boxes.size ())+ " \n " ;
210+ out = " MOTResult:\n all boxes counts: " + std::to_string (boxes.size ()) + " \n " ;
183211 out += " [xmin\t ymin\t xmax\t ymax\t id\t score]\n " ;
184212 for (size_t i = 0 ; i < boxes.size (); ++i) {
185- out = out + " [" + std::to_string (boxes[i][0 ]) + " \t " +
213+ out = out + " [" + std::to_string (boxes[i][0 ]) + " \t " +
186214 std::to_string (boxes[i][1 ]) + " \t " + std::to_string (boxes[i][2 ]) +
187- " \t " + std::to_string (boxes[i][3 ]) + " \t " +
188- std::to_string (ids[i]) + " \t " + std::to_string (scores[i]) + " ]\n " ;
215+ " \t " + std::to_string (boxes[i][3 ]) + " \t " + std::to_string (ids[i]) +
216+ " \t " + std::to_string (scores[i]) + " ]\n " ;
189217 }
190218 return out;
191219}
@@ -197,13 +225,20 @@ FaceDetectionResult::FaceDetectionResult(const FaceDetectionResult& res) {
197225 landmarks_per_face = res.landmarks_per_face ;
198226}
199227
200- void FaceDetectionResult::Clear () {
228+ void FaceDetectionResult::Free () {
201229 std::vector<std::array<float , 4 >>().swap (boxes);
202230 std::vector<float >().swap (scores);
203231 std::vector<std::array<float , 2 >>().swap (landmarks);
204232 landmarks_per_face = 0 ;
205233}
206234
235+ void FaceDetectionResult::Clear () {
236+ boxes.clear ();
237+ scores.clear ();
238+ landmarks.clear ();
239+ landmarks_per_face = 0 ;
240+ }
241+
207242void FaceDetectionResult::Reserve (int size) {
208243 boxes.reserve (size);
209244 scores.reserve (size);
@@ -257,23 +292,22 @@ std::string FaceDetectionResult::Str() {
257292 return out;
258293}
259294
260- void FaceAlignmentResult::Clear () {
295+ void FaceAlignmentResult::Free () {
261296 std::vector<std::array<float , 2 >>().swap (landmarks);
262297}
263298
264- void FaceAlignmentResult::Reserve (int size) {
265- landmarks.resize (size);
266- }
299+ void FaceAlignmentResult::Clear () { landmarks.clear (); }
267300
268- void FaceAlignmentResult::Resize (int size) {
269- landmarks. resize (size);
270- }
301+ void FaceAlignmentResult::Reserve (int size) { landmarks. resize (size); }
302+
303+ void FaceAlignmentResult::Resize ( int size) { landmarks. resize (size); }
271304
272305std::string FaceAlignmentResult::Str () {
273306 std::string out;
274307
275308 out = " FaceAlignmentResult: [x, y]\n " ;
276- out = out + " There are " +std::to_string (landmarks.size ()) + " landmarks, the top 10 are listed as below:\n " ;
309+ out = out + " There are " + std::to_string (landmarks.size ()) +
310+ " landmarks, the top 10 are listed as below:\n " ;
277311 int landmarks_size = landmarks.size ();
278312 size_t result_length = std::min (10 , landmarks_size);
279313 for (size_t i = 0 ; i < result_length; ++i) {
@@ -355,7 +389,9 @@ FaceRecognitionResult::FaceRecognitionResult(const FaceRecognitionResult& res) {
355389 embedding.assign (res.embedding .begin (), res.embedding .end ());
356390}
357391
358- void FaceRecognitionResult::Clear () { std::vector<float >().swap (embedding); }
392+ void FaceRecognitionResult::Free () { std::vector<float >().swap (embedding); }
393+
394+ void FaceRecognitionResult::Clear () { embedding.clear (); }
359395
360396void FaceRecognitionResult::Reserve (int size) { embedding.reserve (size); }
361397
@@ -536,28 +572,23 @@ std::string OCRResult::Str() {
536572 return no_result;
537573}
538574
539- void HeadPoseResult::Clear () {
540- std::vector<float >().swap (euler_angles);
541- }
575+ void HeadPoseResult::Free () { std::vector<float >().swap (euler_angles); }
542576
543- void HeadPoseResult::Reserve (int size) {
544- euler_angles.resize (size);
545- }
577+ void HeadPoseResult::Clear () { euler_angles.clear (); }
546578
547- void HeadPoseResult::Resize (int size) {
548- euler_angles. resize (size);
549- }
579+ void HeadPoseResult::Reserve (int size) { euler_angles. resize (size); }
580+
581+ void HeadPoseResult::Resize ( int size) { euler_angles. resize (size); }
550582
551583std::string HeadPoseResult::Str () {
552584 std::string out;
553585
554586 out = " HeadPoseResult: [yaw, pitch, roll]\n " ;
555- out = out + " yaw: " + std::to_string (euler_angles[0 ]) + " \n " +
556- " pitch: " + std::to_string (euler_angles[1 ]) + " \n " +
557- " roll: " + std::to_string (euler_angles[2 ]) + " \n " ;
587+ out = out + " yaw: " + std::to_string (euler_angles[0 ]) + " \n " + " pitch: " +
588+ std::to_string (euler_angles[1 ]) + " \n " + " roll: " +
589+ std::to_string (euler_angles[2 ]) + " \n " ;
558590 return out;
559591}
560592
561-
562593} // namespace vision
563594} // namespace fastdeploy
0 commit comments