Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
de726400
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
大约 2 年 前同步成功
通知
118
Star
4999
Fork
1114
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
6
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleClas
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
6
合并请求
6
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
de726400
编写于
12月 01, 2021
作者:
D
dongshuilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code format
上级
87873447
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
360 addition
and
358 deletion
+360
-358
deploy/cpp/readme.md
deploy/cpp/readme.md
+2
-2
deploy/cpp_shitu/src/feature_extracter.cpp
deploy/cpp_shitu/src/feature_extracter.cpp
+96
-96
deploy/cpp_shitu/src/main.cpp
deploy/cpp_shitu/src/main.cpp
+262
-260
未找到文件。
deploy/cpp/readme.md
浏览文件 @
de726400
...
@@ -215,9 +215,9 @@ cp ../configs/inference_cls.yaml tools/
...
@@ -215,9 +215,9 @@ cp ../configs/inference_cls.yaml tools/
#### 2.3.2 执行
#### 2.3.2 执行
```
shell
```
shell
./build/clas_system
-c
inference_cls.yaml
./build/clas_system
-c
tools/
inference_cls.yaml
# or
# or
./build/clas_system
-config
inference_cls.yaml
./build/clas_system
-config
tools/
inference_cls.yaml
```
```
最终屏幕上会输出结果,如下图所示。
最终屏幕上会输出结果,如下图所示。
...
...
deploy/cpp_shitu/src/feature_extracter.cpp
浏览文件 @
de726400
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
namespace
Feature
{
namespace
Feature
{
void
FeatureExtracter
::
LoadModel
(
const
std
::
string
&
model_path
,
void
FeatureExtracter
::
LoadModel
(
const
std
::
string
&
model_path
,
const
std
::
string
&
params_path
)
{
const
std
::
string
&
params_path
)
{
paddle_infer
::
Config
config
;
paddle_infer
::
Config
config
;
config
.
SetModel
(
model_path
,
params_path
);
config
.
SetModel
(
model_path
,
params_path
);
...
@@ -52,9 +52,9 @@ void FeatureExtracter::LoadModel(const std::string &model_path,
...
@@ -52,9 +52,9 @@ void FeatureExtracter::LoadModel(const std::string &model_path,
config
.
DisableGlogInfo
();
config
.
DisableGlogInfo
();
this
->
predictor_
=
CreatePredictor
(
config
);
this
->
predictor_
=
CreatePredictor
(
config
);
}
}
void
FeatureExtracter
::
Run
(
cv
::
Mat
&
img
,
std
::
vector
<
float
>
&
out_data
,
void
FeatureExtracter
::
Run
(
cv
::
Mat
&
img
,
std
::
vector
<
float
>
&
out_data
,
std
::
vector
<
double
>
&
times
)
{
std
::
vector
<
double
>
&
times
)
{
cv
::
Mat
resize_img
;
cv
::
Mat
resize_img
;
std
::
vector
<
double
>
time
;
std
::
vector
<
double
>
time
;
...
@@ -108,12 +108,12 @@ void FeatureExtracter::Run(cv::Mat &img, std::vector<float> &out_data,
...
@@ -108,12 +108,12 @@ void FeatureExtracter::Run(cv::Mat &img, std::vector<float> &out_data,
times
[
0
]
+=
time
[
0
];
times
[
0
]
+=
time
[
0
];
times
[
1
]
+=
time
[
1
];
times
[
1
]
+=
time
[
1
];
times
[
2
]
+=
time
[
2
];
times
[
2
]
+=
time
[
2
];
}
}
void
FeatureExtracter
::
FeatureNorm
(
std
::
vector
<
float
>
&
featuer
)
{
void
FeatureExtracter
::
FeatureNorm
(
std
::
vector
<
float
>
&
featuer
)
{
float
featuer_sqrt
=
std
::
sqrt
(
std
::
inner_product
(
float
featuer_sqrt
=
std
::
sqrt
(
std
::
inner_product
(
featuer
.
begin
(),
featuer
.
end
(),
featuer
.
begin
(),
0.0
f
));
featuer
.
begin
(),
featuer
.
end
(),
featuer
.
begin
(),
0.0
f
));
for
(
int
i
=
0
;
i
<
featuer
.
size
();
++
i
)
for
(
int
i
=
0
;
i
<
featuer
.
size
();
++
i
)
featuer
[
i
]
/=
featuer_sqrt
;
featuer
[
i
]
/=
featuer_sqrt
;
}
}
}
// namespace Feature
}
// namespace Feature
deploy/cpp_shitu/src/main.cpp
浏览文件 @
de726400
...
@@ -37,13 +37,15 @@
...
@@ -37,13 +37,15 @@
using
namespace
std
;
using
namespace
std
;
using
namespace
cv
;
using
namespace
cv
;
DEFINE_string
(
config
,
""
,
"Path of yaml file"
);
DEFINE_string
(
config
,
DEFINE_string
(
c
,
""
,
"Path of yaml file"
);
""
,
"Path of yaml file"
);
DEFINE_string
(
c
,
""
,
"Path of yaml file"
);
void
DetPredictImage
(
const
std
::
vector
<
cv
::
Mat
>
&
batch_imgs
,
void
DetPredictImage
(
const
std
::
vector
<
cv
::
Mat
>
&
batch_imgs
,
const
std
::
vector
<
std
::
string
>
&
all_img_paths
,
const
std
::
vector
<
std
::
string
>
&
all_img_paths
,
const
int
batch_size
,
Detection
::
ObjectDetector
*
det
,
const
int
batch_size
,
Detection
::
ObjectDetector
*
det
,
std
::
vector
<
Detection
::
ObjectResult
>
&
im_result
,
std
::
vector
<
Detection
::
ObjectResult
>
&
im_result
,
std
::
vector
<
int
>
&
im_bbox_num
,
std
::
vector
<
double
>
&
det_t
,
std
::
vector
<
int
>
&
im_bbox_num
,
std
::
vector
<
double
>
&
det_t
,
const
bool
visual_det
=
false
,
const
bool
visual_det
=
false
,
const
bool
run_benchmark
=
false
,
const
bool
run_benchmark
=
false
,
...
@@ -63,7 +65,7 @@ void DetPredictImage(const std::vector<cv::Mat> &batch_imgs,
...
@@ -63,7 +65,7 @@ void DetPredictImage(const std::vector<cv::Mat> &batch_imgs,
// }
// }
// Store all detected result
// Store all detected result
std
::
vector
<
Detection
::
ObjectResult
>
result
;
std
::
vector
<
Detection
::
ObjectResult
>
result
;
std
::
vector
<
int
>
bbox_num
;
std
::
vector
<
int
>
bbox_num
;
std
::
vector
<
double
>
det_times
;
std
::
vector
<
double
>
det_times
;
bool
is_rbox
=
false
;
bool
is_rbox
=
false
;
...
@@ -134,7 +136,7 @@ void DetPredictImage(const std::vector<cv::Mat> &batch_imgs,
...
@@ -134,7 +136,7 @@ void DetPredictImage(const std::vector<cv::Mat> &batch_imgs,
}
}
void
PrintResult
(
std
::
string
&
img_path
,
void
PrintResult
(
std
::
string
&
img_path
,
std
::
vector
<
Detection
::
ObjectResult
>
&
det_result
,
std
::
vector
<
Detection
::
ObjectResult
>
&
det_result
,
std
::
vector
<
int
>
&
indeices
,
VectorSearch
&
vector_search
,
std
::
vector
<
int
>
&
indeices
,
VectorSearch
&
vector_search
,
SearchResult
&
search_result
)
{
SearchResult
&
search_result
)
{
printf
(
"%s:
\n
"
,
img_path
.
c_str
());
printf
(
"%s:
\n
"
,
img_path
.
c_str
());
...
@@ -194,9 +196,9 @@ int main(int argc, char **argv) {
...
@@ -194,9 +196,9 @@ int main(int argc, char **argv) {
// load image_file_path
// load image_file_path
std
::
string
path
=
std
::
string
path
=
config
.
config_file
[
"Global"
][
"infer_imgs"
].
as
<
std
::
string
>
();
config
.
config_file
[
"Global"
][
"infer_imgs"
].
as
<
std
::
string
>
();
std
::
vector
<
std
::
string
>
img_files_list
;
std
::
vector
<
std
::
string
>
img_files_list
;
if
(
cv
::
utils
::
fs
::
isDirectory
(
path
))
{
if
(
cv
::
utils
::
fs
::
isDirectory
(
path
))
{
std
::
vector
<
cv
::
String
>
filenames
;
std
::
vector
<
cv
::
String
>
filenames
;
cv
::
glob
(
path
,
filenames
);
cv
::
glob
(
path
,
filenames
);
for
(
auto
f
:
filenames
)
{
for
(
auto
f
:
filenames
)
{
img_files_list
.
push_back
(
f
);
img_files_list
.
push_back
(
f
);
...
@@ -211,10 +213,10 @@ int main(int argc, char **argv) {
...
@@ -211,10 +213,10 @@ int main(int argc, char **argv) {
std
::
vector
<
double
>
search_times
=
{
0
,
0
,
0
};
std
::
vector
<
double
>
search_times
=
{
0
,
0
,
0
};
int
instance_num
=
0
;
int
instance_num
=
0
;
// for read images
// for read images
std
::
vector
<
cv
::
Mat
>
batch_imgs
;
std
::
vector
<
cv
::
Mat
>
batch_imgs
;
std
::
vector
<
std
::
string
>
img_paths
;
std
::
vector
<
std
::
string
>
img_paths
;
// for detection
// for detection
std
::
vector
<
Detection
::
ObjectResult
>
det_result
;
std
::
vector
<
Detection
::
ObjectResult
>
det_result
;
std
::
vector
<
int
>
det_bbox_num
;
std
::
vector
<
int
>
det_bbox_num
;
// for vector search
// for vector search
std
::
vector
<
float
>
features
;
std
::
vector
<
float
>
features
;
...
@@ -318,7 +320,7 @@ int main(int argc, char **argv) {
...
@@ -318,7 +320,7 @@ int main(int argc, char **argv) {
config
.
config_file
[
"Global"
][
"cpu_num_threads"
].
as
<
int
>
();
config
.
config_file
[
"Global"
][
"cpu_num_threads"
].
as
<
int
>
();
int
batch_size
=
config
.
config_file
[
"Global"
][
"batch_size"
].
as
<
int
>
();
int
batch_size
=
config
.
config_file
[
"Global"
][
"batch_size"
].
as
<
int
>
();
std
::
vector
<
int
>
shape
=
std
::
vector
<
int
>
shape
=
config
.
config_file
[
"Global"
][
"image_shape"
].
as
<
std
::
vector
<
int
>>
();
config
.
config_file
[
"Global"
][
"image_shape"
].
as
<
std
::
vector
<
int
>>
();
std
::
string
det_shape
=
std
::
to_string
(
shape
[
0
]);
std
::
string
det_shape
=
std
::
to_string
(
shape
[
0
]);
for
(
int
i
=
1
;
i
<
shape
.
size
();
++
i
)
for
(
int
i
=
1
;
i
<
shape
.
size
();
++
i
)
det_shape
=
det_shape
+
", "
+
std
::
to_string
(
shape
[
i
]);
det_shape
=
det_shape
+
", "
+
std
::
to_string
(
shape
[
i
]);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录