Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleSlim
提交
64ebffc4
P
PaddleSlim
项目概览
PaddlePaddle
/
PaddleSlim
大约 1 年 前同步成功
通知
51
Star
1434
Fork
344
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
53
列表
看板
标记
里程碑
合并请求
16
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleSlim
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
53
Issue
53
列表
看板
标记
里程碑
合并请求
16
合并请求
16
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
64ebffc4
编写于
5月 18, 2023
作者:
X
xiaoluomi
提交者:
GitHub
5月 18, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix detection infer (#1751)
上级
da3ef32e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
22 addition
and
58 deletion
+22
-58
example/auto_compression/detection/configs/rtdetr_reader.yml
example/auto_compression/detection/configs/rtdetr_reader.yml
+12
-0
example/auto_compression/detection/paddle_inference_eval.py
example/auto_compression/detection/paddle_inference_eval.py
+10
-58
未找到文件。
example/auto_compression/detection/configs/rtdetr_reader.yml
浏览文件 @
64ebffc4
...
@@ -12,6 +12,18 @@ TrainDataset:
...
@@ -12,6 +12,18 @@ TrainDataset:
anno_path
:
annotations/instances_val2017.json
anno_path
:
annotations/instances_val2017.json
dataset_dir
:
dataset/coco/
dataset_dir
:
dataset/coco/
EvalDataset
:
!COCODataSet
image_dir
:
val2017
anno_path
:
annotations/instances_val2017.json
dataset_dir
:
dataset/coco/
TestDataset
:
!COCODataSet
image_dir
:
val2017
anno_path
:
annotations/instances_val2017.json
dataset_dir
:
dataset/coco/
worker_num
:
0
worker_num
:
0
# preprocess reader in test
# preprocess reader in test
...
...
example/auto_compression/detection/paddle_inference_eval.py
浏览文件 @
64ebffc4
...
@@ -64,7 +64,8 @@ def argsparser():
...
@@ -64,7 +64,8 @@ def argsparser():
"--device"
,
"--device"
,
type
=
str
,
type
=
str
,
default
=
"GPU"
,
default
=
"GPU"
,
help
=
"Choose the device you want to run, it can be: CPU/GPU/XPU, default is GPU"
,
help
=
"Choose the device you want to run, it can be: CPU/GPU/XPU, default is GPU"
,
)
)
parser
.
add_argument
(
parser
.
add_argument
(
"--use_dynamic_shape"
,
"--use_dynamic_shape"
,
...
@@ -270,8 +271,8 @@ def load_predictor(
...
@@ -270,8 +271,8 @@ def load_predictor(
dynamic_shape_file
=
os
.
path
.
join
(
FLAGS
.
model_path
,
dynamic_shape_file
=
os
.
path
.
join
(
FLAGS
.
model_path
,
"dynamic_shape.txt"
)
"dynamic_shape.txt"
)
if
os
.
path
.
exists
(
dynamic_shape_file
):
if
os
.
path
.
exists
(
dynamic_shape_file
):
config
.
enable_tuned_tensorrt_dynamic_shape
(
dynamic_shape_file
,
config
.
enable_tuned_tensorrt_dynamic_shape
(
True
)
dynamic_shape_file
,
True
)
print
(
"trt set dynamic shape done!"
)
print
(
"trt set dynamic shape done!"
)
else
:
else
:
config
.
collect_shape_range_info
(
dynamic_shape_file
)
config
.
collect_shape_range_info
(
dynamic_shape_file
)
...
@@ -284,48 +285,6 @@ def load_predictor(
...
@@ -284,48 +285,6 @@ def load_predictor(
return
predictor
,
rerun_flag
return
predictor
,
rerun_flag
def
get_current_memory_mb
():
"""
It is used to Obtain the memory usage of the CPU and GPU during the running of the program.
And this function Current program is time-consuming.
"""
try
:
pkg
.
require
(
'pynvml'
)
except
:
from
pip._internal
import
main
main
([
'install'
,
'pynvml'
])
try
:
pkg
.
require
(
'psutil'
)
except
:
from
pip._internal
import
main
main
([
'install'
,
'psutil'
])
try
:
pkg
.
require
(
'GPUtil'
)
except
:
from
pip._internal
import
main
main
([
'install'
,
'GPUtil'
])
import
pynvml
import
psutil
import
GPUtil
gpu_id
=
int
(
os
.
environ
.
get
(
"CUDA_VISIBLE_DEVICES"
,
0
))
pid
=
os
.
getpid
()
p
=
psutil
.
Process
(
pid
)
info
=
p
.
memory_full_info
()
cpu_mem
=
info
.
uss
/
1024.0
/
1024.0
gpu_mem
=
0
gpu_percent
=
0
gpus
=
GPUtil
.
getGPUs
()
if
gpu_id
is
not
None
and
len
(
gpus
)
>
0
:
gpu_percent
=
gpus
[
gpu_id
].
load
pynvml
.
nvmlInit
()
handle
=
pynvml
.
nvmlDeviceGetHandleByIndex
(
0
)
meminfo
=
pynvml
.
nvmlDeviceGetMemoryInfo
(
handle
)
gpu_mem
=
meminfo
.
used
/
1024.0
/
1024.0
return
round
(
cpu_mem
,
4
),
round
(
gpu_mem
,
4
)
def
predict_image
(
predictor
,
def
predict_image
(
predictor
,
image_file
,
image_file
,
image_shape
=
[
640
,
640
],
image_shape
=
[
640
,
640
],
...
@@ -353,6 +312,7 @@ def predict_image(predictor,
...
@@ -353,6 +312,7 @@ def predict_image(predictor,
predict_time
=
0.0
predict_time
=
0.0
time_min
=
float
(
"inf"
)
time_min
=
float
(
"inf"
)
time_max
=
float
(
"-inf"
)
time_max
=
float
(
"-inf"
)
paddle
.
device
.
cuda
.
synchronize
()
for
i
in
range
(
repeats
):
for
i
in
range
(
repeats
):
start_time
=
time
.
time
()
start_time
=
time
.
time
()
predictor
.
run
()
predictor
.
run
()
...
@@ -367,13 +327,8 @@ def predict_image(predictor,
...
@@ -367,13 +327,8 @@ def predict_image(predictor,
time_min
=
min
(
time_min
,
timed
)
time_min
=
min
(
time_min
,
timed
)
time_max
=
max
(
time_max
,
timed
)
time_max
=
max
(
time_max
,
timed
)
predict_time
+=
timed
predict_time
+=
timed
cpu_mem
,
gpu_mem
=
get_current_memory_mb
()
cpu_mems
+=
cpu_mem
gpu_mems
+=
gpu_mem
time_avg
=
predict_time
/
repeats
time_avg
=
predict_time
/
repeats
print
(
"[Benchmark]Avg cpu_mem:{} MB, avg gpu_mem: {} MB"
.
format
(
cpu_mems
/
repeats
,
gpu_mems
/
repeats
))
print
(
"[Benchmark]Inference time(ms): min={}, max={}, avg={}"
.
format
(
print
(
"[Benchmark]Inference time(ms): min={}, max={}, avg={}"
.
format
(
round
(
time_min
*
1000
,
2
),
round
(
time_min
*
1000
,
2
),
round
(
time_max
*
1000
,
1
),
round
(
time_avg
*
1000
,
1
)))
round
(
time_max
*
1000
,
1
),
round
(
time_avg
*
1000
,
1
)))
...
@@ -406,6 +361,7 @@ def eval(predictor, val_loader, metric, rerun_flag=False):
...
@@ -406,6 +361,7 @@ def eval(predictor, val_loader, metric, rerun_flag=False):
for
i
,
_
in
enumerate
(
input_names
):
for
i
,
_
in
enumerate
(
input_names
):
input_tensor
=
predictor
.
get_input_handle
(
input_names
[
i
])
input_tensor
=
predictor
.
get_input_handle
(
input_names
[
i
])
input_tensor
.
copy_from_cpu
(
data_all
[
input_names
[
i
]])
input_tensor
.
copy_from_cpu
(
data_all
[
input_names
[
i
]])
paddle
.
device
.
cuda
.
synchronize
()
start_time
=
time
.
time
()
start_time
=
time
.
time
()
predictor
.
run
()
predictor
.
run
()
np_boxes
=
boxes_tensor
.
copy_to_cpu
()
np_boxes
=
boxes_tensor
.
copy_to_cpu
()
...
@@ -418,9 +374,6 @@ def eval(predictor, val_loader, metric, rerun_flag=False):
...
@@ -418,9 +374,6 @@ def eval(predictor, val_loader, metric, rerun_flag=False):
time_min
=
min
(
time_min
,
timed
)
time_min
=
min
(
time_min
,
timed
)
time_max
=
max
(
time_max
,
timed
)
time_max
=
max
(
time_max
,
timed
)
predict_time
+=
timed
predict_time
+=
timed
cpu_mem
,
gpu_mem
=
get_current_memory_mb
()
cpu_mems
+=
cpu_mem
gpu_mems
+=
gpu_mem
if
not
FLAGS
.
include_nms
:
if
not
FLAGS
.
include_nms
:
postprocess
=
PPYOLOEPostProcess
(
postprocess
=
PPYOLOEPostProcess
(
score_threshold
=
0.3
,
nms_threshold
=
0.6
)
score_threshold
=
0.3
,
nms_threshold
=
0.6
)
...
@@ -436,8 +389,6 @@ def eval(predictor, val_loader, metric, rerun_flag=False):
...
@@ -436,8 +389,6 @@ def eval(predictor, val_loader, metric, rerun_flag=False):
map_res
=
metric
.
get_results
()
map_res
=
metric
.
get_results
()
metric
.
reset
()
metric
.
reset
()
time_avg
=
predict_time
/
sample_nums
time_avg
=
predict_time
/
sample_nums
print
(
"[Benchmark]Avg cpu_mem:{} MB, avg gpu_mem: {} MB"
.
format
(
cpu_mems
/
sample_nums
,
gpu_mems
/
sample_nums
))
print
(
"[Benchmark]Inference time(ms): min={}, max={}, avg={}"
.
format
(
print
(
"[Benchmark]Inference time(ms): min={}, max={}, avg={}"
.
format
(
round
(
time_min
*
1000
,
2
),
round
(
time_min
*
1000
,
2
),
round
(
time_max
*
1000
,
1
),
round
(
time_avg
*
1000
,
1
)))
round
(
time_max
*
1000
,
1
),
round
(
time_avg
*
1000
,
1
)))
...
@@ -473,9 +424,10 @@ def main():
...
@@ -473,9 +424,10 @@ def main():
dataset
=
reader_cfg
[
"EvalDataset"
]
dataset
=
reader_cfg
[
"EvalDataset"
]
global
val_loader
global
val_loader
val_loader
=
create
(
"EvalReader"
)(
reader_cfg
[
"EvalDataset"
],
val_loader
=
create
(
"EvalReader"
)(
reader_cfg
[
"worker_num"
],
reader_cfg
[
"EvalDataset"
],
return_list
=
True
)
reader_cfg
[
"worker_num"
],
return_list
=
True
)
clsid2catid
=
{
v
:
k
for
k
,
v
in
dataset
.
catid2clsid
.
items
()}
clsid2catid
=
{
v
:
k
for
k
,
v
in
dataset
.
catid2clsid
.
items
()}
anno_file
=
dataset
.
get_anno
()
anno_file
=
dataset
.
get_anno
()
metric
=
COCOMetric
(
metric
=
COCOMetric
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录