Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleClas
提交
27013344
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看板
未验证
提交
27013344
编写于
12月 01, 2020
作者:
mikeshi1980
提交者:
GitHub
12月 01, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加对一个目录的文件的支持 (#427)
上级
18d27608
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
29 addition
and
14 deletion
+29
-14
tools/infer/predict.py
tools/infer/predict.py
+29
-14
未找到文件。
tools/infer/predict.py
浏览文件 @
27013344
...
@@ -30,6 +30,7 @@ def parse_args():
...
@@ -30,6 +30,7 @@ def parse_args():
parser
=
argparse
.
ArgumentParser
()
parser
=
argparse
.
ArgumentParser
()
parser
.
add_argument
(
"-i"
,
"--image_file"
,
type
=
str
)
parser
.
add_argument
(
"-i"
,
"--image_file"
,
type
=
str
)
parser
.
add_argument
(
"-d"
,
"--image_dir"
,
type
=
str
)
parser
.
add_argument
(
"-m"
,
"--model_file"
,
type
=
str
)
parser
.
add_argument
(
"-m"
,
"--model_file"
,
type
=
str
)
parser
.
add_argument
(
"-p"
,
"--params_file"
,
type
=
str
)
parser
.
add_argument
(
"-p"
,
"--params_file"
,
type
=
str
)
parser
.
add_argument
(
"-b"
,
"--batch_size"
,
type
=
int
,
default
=
1
)
parser
.
add_argument
(
"-b"
,
"--batch_size"
,
type
=
int
,
default
=
1
)
...
@@ -93,6 +94,8 @@ def preprocess(fname, ops):
...
@@ -93,6 +94,8 @@ def preprocess(fname, ops):
def
main
():
def
main
():
import
os
args
=
parse_args
()
args
=
parse_args
()
if
not
args
.
enable_benchmark
:
if
not
args
.
enable_benchmark
:
...
@@ -102,6 +105,8 @@ def main():
...
@@ -102,6 +105,8 @@ def main():
assert
args
.
use_gpu
is
True
assert
args
.
use_gpu
is
True
assert
args
.
model_name
is
not
None
assert
args
.
model_name
is
not
None
assert
args
.
use_tensorrt
is
True
assert
args
.
use_tensorrt
is
True
assert
args
.
image_file
is
not
None
# HALF precission predict only work when using tensorrt
# HALF precission predict only work when using tensorrt
if
args
.
use_fp16
is
True
:
if
args
.
use_fp16
is
True
:
assert
args
.
use_tensorrt
is
True
assert
args
.
use_tensorrt
is
True
...
@@ -118,20 +123,30 @@ def main():
...
@@ -118,20 +123,30 @@ def main():
test_num
=
500
test_num
=
500
test_time
=
0.0
test_time
=
0.0
if
not
args
.
enable_benchmark
:
if
not
args
.
enable_benchmark
:
inputs
=
preprocess
(
args
.
image_file
,
operators
)
image_files
=
[]
inputs
=
np
.
expand_dims
(
if
args
.
image_file
is
not
None
:
inputs
,
axis
=
0
).
repeat
(
image_files
=
[
args
.
image_file
]
args
.
batch_size
,
axis
=
0
).
copy
()
elif
args
.
image_dir
is
not
None
:
input_tensor
.
copy_from_cpu
(
inputs
)
supported_exts
=
(
'.jpg'
,
'jpeg'
,
'.png'
,
'.gif'
,
'.bmp'
)
for
root
,
_
,
files
in
os
.
walk
(
args
.
image_dir
,
topdown
=
False
):
predictor
.
zero_copy_run
()
image_files
+=
[
os
.
path
.
join
(
root
,
f
)
for
f
in
files
if
os
.
path
.
splitext
(
f
)[
-
1
].
lower
()
in
supported_exts
]
output
=
output_tensor
.
copy_to_cpu
()
for
image_file
in
image_files
:
output
=
output
.
flatten
()
inputs
=
preprocess
(
image_file
,
operators
)
cls
=
np
.
argmax
(
output
)
inputs
=
np
.
expand_dims
(
score
=
output
[
cls
]
inputs
,
axis
=
0
).
repeat
(
logger
.
info
(
"class: {0}"
.
format
(
cls
))
args
.
batch_size
,
axis
=
0
).
copy
()
logger
.
info
(
"score: {0}"
.
format
(
score
))
input_tensor
.
copy_from_cpu
(
inputs
)
predictor
.
zero_copy_run
()
output
=
output_tensor
.
copy_to_cpu
()
output
=
output
.
flatten
()
cls
=
np
.
argmax
(
output
)
score
=
output
[
cls
]
logger
.
info
(
"image file: {0}"
.
format
(
image_file
))
logger
.
info
(
"class: {0}"
.
format
(
cls
))
logger
.
info
(
"score: {0}"
.
format
(
score
))
else
:
else
:
for
i
in
range
(
0
,
test_num
+
10
):
for
i
in
range
(
0
,
test_num
+
10
):
inputs
=
np
.
random
.
rand
(
args
.
batch_size
,
3
,
224
,
inputs
=
np
.
random
.
rand
(
args
.
batch_size
,
3
,
224
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录