Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
c3922941
P
PaddleClas
项目概览
PaddlePaddle
/
PaddleClas
大约 1 年 前同步成功
通知
115
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看板
未验证
提交
c3922941
编写于
11月 04, 2020
作者:
L
littletomatodonkey
提交者:
GitHub
11月 04, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix dist training (#363)
1. fix dist training 2. fix cpp infer to support dir inference
上级
53eda593
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
43 addition
and
23 deletion
+43
-23
deploy/cpp_infer/src/main.cpp
deploy/cpp_infer/src/main.cpp
+36
-13
tools/program.py
tools/program.py
+4
-9
tools/train.py
tools/train.py
+3
-1
未找到文件。
deploy/cpp_infer/src/main.cpp
浏览文件 @
c3922941
...
...
@@ -18,6 +18,7 @@
#include <chrono>
#include <iomanip>
#include <iostream>
#include <opencv2/core/utils/filesystem.hpp>
#include <ostream>
#include <vector>
...
...
@@ -43,26 +44,48 @@ int main(int argc, char **argv) {
config
.
PrintConfigInfo
();
std
::
string
img_
path
(
argv
[
2
]);
std
::
string
path
(
argv
[
2
]);
cv
::
Mat
srcimg
=
cv
::
imread
(
img_path
,
cv
::
IMREAD_COLOR
);
cv
::
cvtColor
(
srcimg
,
srcimg
,
cv
::
COLOR_BGR2RGB
);
std
::
vector
<
std
::
string
>
img_files_list
;
if
(
cv
::
utils
::
fs
::
isDirectory
(
path
))
{
std
::
vector
<
cv
::
String
>
filenames
;
cv
::
glob
(
path
,
filenames
);
for
(
auto
f
:
filenames
)
{
img_files_list
.
push_back
(
f
);
}
}
else
{
img_files_list
.
push_back
(
path
);
}
std
::
cout
<<
"img_file_list length: "
<<
img_files_list
.
size
()
<<
std
::
endl
;
Classifier
classifier
(
config
.
cls_model_dir
,
config
.
use_gpu
,
config
.
gpu_id
,
config
.
gpu_mem
,
config
.
cpu_math_library_num_threads
,
config
.
use_mkldnn
,
config
.
use_zero_copy_run
,
config
.
resize_short_size
,
config
.
crop_size
);
auto
start
=
std
::
chrono
::
system_clock
::
now
();
classifier
.
Run
(
srcimg
);
auto
end
=
std
::
chrono
::
system_clock
::
now
();
auto
duration
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
end
-
start
);
std
::
cout
<<
"Cost "
<<
double
(
duration
.
count
())
*
std
::
chrono
::
microseconds
::
period
::
num
/
std
::
chrono
::
microseconds
::
period
::
den
<<
" s"
<<
std
::
endl
;
double
elapsed_time
=
0.0
;
int
warmup_iter
=
img_files_list
.
size
()
>
5
?
5
:
0
;
for
(
int
idx
=
0
;
idx
<
img_files_list
.
size
();
++
idx
)
{
std
::
string
img_path
=
img_files_list
[
idx
];
cv
::
Mat
srcimg
=
cv
::
imread
(
img_path
,
cv
::
IMREAD_COLOR
);
cv
::
cvtColor
(
srcimg
,
srcimg
,
cv
::
COLOR_BGR2RGB
);
auto
start
=
std
::
chrono
::
system_clock
::
now
();
classifier
.
Run
(
srcimg
);
auto
end
=
std
::
chrono
::
system_clock
::
now
();
auto
duration
=
std
::
chrono
::
duration_cast
<
std
::
chrono
::
microseconds
>
(
end
-
start
);
double
curr_time
=
double
(
duration
.
count
())
*
std
::
chrono
::
microseconds
::
period
::
num
/
std
::
chrono
::
microseconds
::
period
::
den
;
if
(
idx
>=
warmup_iter
)
{
elapsed_time
+=
curr_time
;
}
std
::
cout
<<
"Current time cost: "
<<
curr_time
<<
" s, "
<<
"average time cost in all: "
<<
elapsed_time
/
(
idx
+
1
-
warmup_iter
)
<<
" s."
<<
std
::
endl
;
}
return
0
;
}
tools/program.py
浏览文件 @
c3922941
...
...
@@ -295,16 +295,11 @@ def run(dataloader,
feeds
=
create_feeds
(
batch
,
use_mix
)
fetchs
=
create_fetchs
(
feeds
,
net
,
config
,
mode
)
if
mode
==
'train'
:
if
config
[
"use_data_parallel"
]:
avg_loss
=
net
.
scale_loss
(
fetchs
[
'loss'
])
avg_loss
.
backward
()
net
.
apply_collective_grads
()
else
:
avg_loss
=
fetchs
[
'loss'
]
avg_loss
.
backward
()
avg_loss
=
fetchs
[
'loss'
]
avg_loss
.
backward
()
optimizer
.
minimize
(
avg_loss
)
net
.
clear_gradients
()
optimizer
.
step
(
)
optimizer
.
clear_grad
()
metric_list
[
'lr'
].
update
(
optimizer
.
_global_learning_rate
().
numpy
()[
0
],
batch_size
)
...
...
tools/train.py
浏览文件 @
c3922941
...
...
@@ -63,13 +63,15 @@ def main(args):
use_data_parallel
=
int
(
os
.
getenv
(
"PADDLE_TRAINERS_NUM"
,
1
))
!=
1
config
[
"use_data_parallel"
]
=
use_data_parallel
if
config
[
"use_data_parallel"
]:
strategy
=
paddle
.
distributed
.
init_parallel_env
()
net
=
program
.
create_model
(
config
.
ARCHITECTURE
,
config
.
classes_num
)
optimizer
,
lr_scheduler
=
program
.
create_optimizer
(
config
,
parameter_list
=
net
.
parameters
())
if
config
[
"use_data_parallel"
]:
strategy
=
paddle
.
distributed
.
init_parallel_env
()
net
=
paddle
.
DataParallel
(
net
,
strategy
)
# load model from checkpoint or pretrained model
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录