1
- /* **************************************************************************
2
- *
3
- * Copyright (c) 2021 Baidu.com, Inc. All Rights Reserved
4
- *
5
- **************************************************************************/
6
-
7
- /* *
8
- * @author Baidu
9
- * @brief demo_image_inference
10
- *
11
- **/
1
+ // Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
12
15
#include " fastdeploy/vision.h"
13
16
14
17
void CpuInfer (const std::string &model_file, const std::string ¶ms_file,
@@ -28,8 +31,8 @@ void CpuInfer(const std::string &model_file, const std::string ¶ms_file,
28
31
fastdeploy::vision::FaceRecognitionResult res1;
29
32
fastdeploy::vision::FaceRecognitionResult res2;
30
33
31
- if ((!model.Predict (& face0, &res0)) || (!model.Predict (& face1, &res1)) ||
32
- (!model.Predict (& face2, &res2))) {
34
+ if ((!model.Predict (face0, &res0)) || (!model.Predict (face1, &res1)) ||
35
+ (!model.Predict (face2, &res2))) {
33
36
std::cerr << " Prediction Failed." << std::endl;
34
37
}
35
38
@@ -40,9 +43,11 @@ void CpuInfer(const std::string &model_file, const std::string ¶ms_file,
40
43
std::cout << " --- [Face 2]:" << res2.Str ();
41
44
42
45
float cosine01 = fastdeploy::vision::utils::CosineSimilarity (
43
- res0.embedding , res1.embedding , model.l2_normalize );
46
+ res0.embedding , res1.embedding ,
47
+ model.GetPostprocessor ().GetL2Normalize ());
44
48
float cosine02 = fastdeploy::vision::utils::CosineSimilarity (
45
- res0.embedding , res2.embedding , model.l2_normalize );
49
+ res0.embedding , res2.embedding ,
50
+ model.GetPostprocessor ().GetL2Normalize ());
46
51
std::cout << " Detect Done! Cosine 01: " << cosine01
47
52
<< " , Cosine 02:" << cosine02 << std::endl;
48
53
}
@@ -65,8 +70,8 @@ void XpuInfer(const std::string &model_file, const std::string ¶ms_file,
65
70
fastdeploy::vision::FaceRecognitionResult res1;
66
71
fastdeploy::vision::FaceRecognitionResult res2;
67
72
68
- if ((!model.Predict (& face0, &res0)) || (!model.Predict (& face1, &res1)) ||
69
- (!model.Predict (& face2, &res2))) {
73
+ if ((!model.Predict (face0, &res0)) || (!model.Predict (face1, &res1)) ||
74
+ (!model.Predict (face2, &res2))) {
70
75
std::cerr << " Prediction Failed." << std::endl;
71
76
}
72
77
@@ -77,9 +82,11 @@ void XpuInfer(const std::string &model_file, const std::string ¶ms_file,
77
82
std::cout << " --- [Face 2]:" << res2.Str ();
78
83
79
84
float cosine01 = fastdeploy::vision::utils::CosineSimilarity (
80
- res0.embedding , res1.embedding , model.l2_normalize );
85
+ res0.embedding , res1.embedding ,
86
+ model.GetPostprocessor ().GetL2Normalize ());
81
87
float cosine02 = fastdeploy::vision::utils::CosineSimilarity (
82
- res0.embedding , res2.embedding , model.l2_normalize );
88
+ res0.embedding , res2.embedding ,
89
+ model.GetPostprocessor ().GetL2Normalize ());
83
90
std::cout << " Detect Done! Cosine 01: " << cosine01
84
91
<< " , Cosine 02:" << cosine02 << std::endl;
85
92
}
@@ -103,8 +110,8 @@ void GpuInfer(const std::string &model_file, const std::string ¶ms_file,
103
110
fastdeploy::vision::FaceRecognitionResult res1;
104
111
fastdeploy::vision::FaceRecognitionResult res2;
105
112
106
- if ((!model.Predict (& face0, &res0)) || (!model.Predict (& face1, &res1)) ||
107
- (!model.Predict (& face2, &res2))) {
113
+ if ((!model.Predict (face0, &res0)) || (!model.Predict (face1, &res1)) ||
114
+ (!model.Predict (face2, &res2))) {
108
115
std::cerr << " Prediction Failed." << std::endl;
109
116
}
110
117
@@ -115,9 +122,11 @@ void GpuInfer(const std::string &model_file, const std::string ¶ms_file,
115
122
std::cout << " --- [Face 2]:" << res2.Str ();
116
123
117
124
float cosine01 = fastdeploy::vision::utils::CosineSimilarity (
118
- res0.embedding , res1.embedding , model.l2_normalize );
125
+ res0.embedding , res1.embedding ,
126
+ model.GetPostprocessor ().GetL2Normalize ());
119
127
float cosine02 = fastdeploy::vision::utils::CosineSimilarity (
120
- res0.embedding , res2.embedding , model.l2_normalize );
128
+ res0.embedding , res2.embedding ,
129
+ model.GetPostprocessor ().GetL2Normalize ());
121
130
std::cout << " Detect Done! Cosine 01: " << cosine01
122
131
<< " , Cosine 02:" << cosine02 << std::endl;
123
132
}
@@ -143,8 +152,8 @@ void TrtInfer(const std::string &model_file, const std::string ¶ms_file,
143
152
fastdeploy::vision::FaceRecognitionResult res1;
144
153
fastdeploy::vision::FaceRecognitionResult res2;
145
154
146
- if ((!model.Predict (& face0, &res0)) || (!model.Predict (& face1, &res1)) ||
147
- (!model.Predict (& face2, &res2))) {
155
+ if ((!model.Predict (face0, &res0)) || (!model.Predict (face1, &res1)) ||
156
+ (!model.Predict (face2, &res2))) {
148
157
std::cerr << " Prediction Failed." << std::endl;
149
158
}
150
159
@@ -155,9 +164,11 @@ void TrtInfer(const std::string &model_file, const std::string ¶ms_file,
155
164
std::cout << " --- [Face 2]:" << res2.Str ();
156
165
157
166
float cosine01 = fastdeploy::vision::utils::CosineSimilarity (
158
- res0.embedding , res1.embedding , model.l2_normalize );
167
+ res0.embedding , res1.embedding ,
168
+ model.GetPostprocessor ().GetL2Normalize ());
159
169
float cosine02 = fastdeploy::vision::utils::CosineSimilarity (
160
- res0.embedding , res2.embedding , model.l2_normalize );
170
+ res0.embedding , res2.embedding ,
171
+ model.GetPostprocessor ().GetL2Normalize ());
161
172
std::cout << " Detect Done! Cosine 01: " << cosine01
162
173
<< " , Cosine 02:" << cosine02 << std::endl;
163
174
}
0 commit comments