Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
e1716ded
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看板
提交
e1716ded
编写于
12月 14, 2021
作者:
D
dongshuilong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
code format for cls class_infer
上级
3e302147
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
359 addition
and
355 deletion
+359
-355
deploy/cpp/docs/imgs/cpp_infer_result.png
deploy/cpp/docs/imgs/cpp_infer_result.png
+0
-0
deploy/cpp/include/cls.h
deploy/cpp/include/cls.h
+44
-44
deploy/cpp/include/cls_config.h
deploy/cpp/include/cls_config.h
+94
-92
deploy/cpp/readme.md
deploy/cpp/readme.md
+1
-1
deploy/cpp/src/cls.cpp
deploy/cpp/src/cls.cpp
+93
-93
deploy/cpp/src/cls_config.cpp
deploy/cpp/src/cls_config.cpp
+28
-28
deploy/cpp/src/main.cpp
deploy/cpp/src/main.cpp
+85
-83
deploy/cpp/src/utility.cpp
deploy/cpp/src/utility.cpp
+14
-14
未找到文件。
deploy/cpp/docs/imgs/cpp_infer_result.png
查看替换文件 @
3e302147
浏览文件 @
e1716ded
85.1 KB
|
W:
|
H:
73.4 KB
|
W:
|
H:
2-up
Swipe
Onion skin
deploy/cpp/include/cls.h
浏览文件 @
e1716ded
...
...
@@ -35,8 +35,8 @@ using namespace paddle_infer;
namespace
PaddleClas
{
class
Classifier
{
public:
class
Classifier
{
public:
explicit
Classifier
(
const
ClsConfig
&
config
)
{
this
->
use_gpu_
=
config
.
use_gpu
;
this
->
gpu_id_
=
config
.
gpu_id
;
...
...
@@ -61,8 +61,8 @@ public:
void
Run
(
cv
::
Mat
&
img
,
std
::
vector
<
float
>
&
out_data
,
std
::
vector
<
int
>
&
idx
,
std
::
vector
<
double
>
&
times
);
private:
std
::
shared_ptr
<
Predictor
>
predictor_
;
private:
std
::
shared_ptr
<
Predictor
>
predictor_
;
bool
use_gpu_
=
false
;
int
gpu_id_
=
0
;
...
...
@@ -85,6 +85,6 @@ private:
Normalize
normalize_op_
;
Permute
permute_op_
;
CenterCropImg
crop_op_
;
};
};
}
// namespace PaddleClas
deploy/cpp/include/cls_config.h
浏览文件 @
e1716ded
...
...
@@ -31,8 +31,8 @@
namespace
PaddleClas
{
class
ClsConfig
{
public:
class
ClsConfig
{
public:
explicit
ClsConfig
(
const
std
::
string
&
path
)
{
ReadYamlConfig
(
path
);
this
->
infer_imgs
=
...
...
@@ -72,10 +72,10 @@ public:
.
as
<
float
>
();
this
->
mean
=
this
->
config_file
[
"PreProcess"
][
"transform_ops"
][
2
]
[
"NormalizeImage"
][
"mean"
]
.
as
<
std
::
vector
<
float
>>
();
.
as
<
std
::
vector
<
float
>>
();
this
->
std
=
this
->
config_file
[
"PreProcess"
][
"transform_ops"
][
2
]
[
"NormalizeImage"
][
"std"
]
.
as
<
std
::
vector
<
float
>>
();
.
as
<
std
::
vector
<
float
>>
();
if
(
this
->
config_file
[
"Global"
][
"benchmark"
].
IsDefined
())
this
->
benchmark
=
this
->
config_file
[
"Global"
][
"benchmark"
].
as
<
bool
>
();
else
...
...
@@ -125,7 +125,9 @@ public:
std
::
string
label_save_dir
;
void
PrintConfigInfo
();
void
ReadLabelMap
();
void
ReadYamlConfig
(
const
std
::
string
&
path
);
};
};
}
// namespace PaddleClas
deploy/cpp/readme.md
浏览文件 @
e1716ded
...
...
@@ -209,7 +209,7 @@ cp ../configs/inference_cls.yaml tools/
根据
[
python预测推理
](
../../docs/zh_CN/inference_deployment/python_deploy.md
)
的
`图像分类推理`
部分修改好
`tools`
目录下
`inference_cls.yaml`
文件。
`yaml`
文件的参数说明详见
[
python预测推理
](
../../docs/zh_CN/inference_deployment/python_deploy.md
)
。
请根据实际存放文件,修改好
`Global.infer_imgs`
、
`Global.inference_model_dir`
等参数。
请根据实际存放文件,修改好
`Global.infer_imgs`
、
`Global.inference_model_dir`
、
`PostProcess.Topk.topk`
、
`PostProcess.Topk.class_id_map_file`
等参数。
#### 2.3.2 执行
...
...
deploy/cpp/src/cls.cpp
浏览文件 @
e1716ded
...
...
@@ -18,7 +18,7 @@
namespace
PaddleClas
{
void
Classifier
::
LoadModel
(
const
std
::
string
&
model_path
,
void
Classifier
::
LoadModel
(
const
std
::
string
&
model_path
,
const
std
::
string
&
params_path
)
{
paddle_infer
::
Config
config
;
config
.
SetModel
(
model_path
,
params_path
);
...
...
@@ -52,9 +52,9 @@ void Classifier::LoadModel(const std::string &model_path,
config
.
DisableGlogInfo
();
this
->
predictor_
=
CreatePredictor
(
config
);
}
}
void
Classifier
::
Run
(
cv
::
Mat
&
img
,
std
::
vector
<
float
>
&
out_data
,
void
Classifier
::
Run
(
cv
::
Mat
&
img
,
std
::
vector
<
float
>
&
out_data
,
std
::
vector
<
int
>
&
idx
,
std
::
vector
<
double
>
&
times
)
{
cv
::
Mat
srcimg
;
cv
::
Mat
resize_img
;
...
...
@@ -112,5 +112,5 @@ void Classifier::Run(cv::Mat &img, std::vector<float> &out_data,
/* std::cout << "\tclass id: " << maxPosition << std::endl; */
/* std::cout << std::fixed << std::setprecision(10) */
/* << "\tscore: " << double(out_data[maxPosition]) << std::endl; */
}
}
}
// namespace PaddleClas
deploy/cpp/src/cls_config.cpp
浏览文件 @
e1716ded
...
...
@@ -17,13 +17,13 @@
namespace
PaddleClas
{
void
ClsConfig
::
PrintConfigInfo
()
{
void
ClsConfig
::
PrintConfigInfo
()
{
std
::
cout
<<
"=======Paddle Class inference config======"
<<
std
::
endl
;
std
::
cout
<<
this
->
config_file
<<
std
::
endl
;
std
::
cout
<<
"=======End of Paddle Class inference config======"
<<
std
::
endl
;
}
}
void
ClsConfig
::
ReadYamlConfig
(
const
std
::
string
&
path
)
{
void
ClsConfig
::
ReadYamlConfig
(
const
std
::
string
&
path
)
{
try
{
this
->
config_file
=
YAML
::
LoadFile
(
path
);
...
...
@@ -32,9 +32,9 @@ void ClsConfig::ReadYamlConfig(const std::string &path) {
<<
std
::
endl
;
exit
(
1
);
}
}
}
void
ClsConfig
::
ReadLabelMap
()
{
void
ClsConfig
::
ReadLabelMap
()
{
if
(
this
->
class_id_map_path
.
empty
())
{
std
::
cout
<<
"The Class Label file dose not input"
<<
std
::
endl
;
return
;
...
...
@@ -48,5 +48,5 @@ void ClsConfig::ReadLabelMap() {
line
.
substr
(
split_flag
+
1
,
line
.
size
());
}
}
}
}
};
// namespace PaddleClas
deploy/cpp/src/main.cpp
浏览文件 @
e1716ded
...
...
@@ -36,8 +36,10 @@ using namespace std;
using
namespace
cv
;
using
namespace
PaddleClas
;
DEFINE_string
(
config
,
""
,
"Path of yaml file"
);
DEFINE_string
(
c
,
""
,
"Path of yaml file"
);
DEFINE_string
(
config
,
""
,
"Path of yaml file"
);
DEFINE_string
(
c
,
""
,
"Path of yaml file"
);
int
main
(
int
argc
,
char
**
argv
)
{
google
::
ParseCommandLineFlags
(
&
argc
,
&
argv
,
true
);
...
...
@@ -58,9 +60,9 @@ int main(int argc, char **argv) {
std
::
string
path
(
config
.
infer_imgs
);
std
::
vector
<
std
::
string
>
img_files_list
;
std
::
vector
<
std
::
string
>
img_files_list
;
if
(
cv
::
utils
::
fs
::
isDirectory
(
path
))
{
std
::
vector
<
cv
::
String
>
filenames
;
std
::
vector
<
cv
::
String
>
filenames
;
cv
::
glob
(
path
,
filenames
);
for
(
auto
f
:
filenames
)
{
img_files_list
.
push_back
(
f
);
...
...
deploy/cpp/src/utility.cpp
浏览文件 @
e1716ded
...
...
@@ -20,10 +20,10 @@
namespace
PaddleClas
{
std
::
vector
<
std
::
string
>
Utility
::
ReadDict
(
const
std
::
string
&
path
)
{
std
::
vector
<
std
::
string
>
Utility
::
ReadDict
(
const
std
::
string
&
path
)
{
std
::
ifstream
in
(
path
);
std
::
string
line
;
std
::
vector
<
std
::
string
>
m_vec
;
std
::
vector
<
std
::
string
>
m_vec
;
if
(
in
)
{
while
(
getline
(
in
,
line
))
{
m_vec
.
push_back
(
line
);
...
...
@@ -34,6 +34,6 @@ std::vector<std::string> Utility::ReadDict(const std::string &path) {
exit
(
1
);
}
return
m_vec
;
}
}
}
// namespace PaddleClas
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录