Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleOCR
提交
a246ab94
P
PaddleOCR
项目概览
s920243400
/
PaddleOCR
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleOCR
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleOCR
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a246ab94
编写于
4月 14, 2022
作者:
T
tink2123
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support xpu for ocr
上级
e4600832
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
23 addition
and
10 deletion
+23
-10
tools/infer/utility.py
tools/infer/utility.py
+3
-1
tools/program.py
tools/program.py
+20
-9
未找到文件。
tools/infer/utility.py
浏览文件 @
a246ab94
...
...
@@ -33,6 +33,7 @@ def init_args():
parser
=
argparse
.
ArgumentParser
()
# params for prediction engine
parser
.
add_argument
(
"--use_gpu"
,
type
=
str2bool
,
default
=
True
)
parser
.
add_argument
(
"--use_xpu"
,
type
=
str2bool
,
default
=
False
)
parser
.
add_argument
(
"--ir_optim"
,
type
=
str2bool
,
default
=
True
)
parser
.
add_argument
(
"--use_tensorrt"
,
type
=
str2bool
,
default
=
False
)
parser
.
add_argument
(
"--min_subgraph_size"
,
type
=
int
,
default
=
15
)
...
...
@@ -277,6 +278,8 @@ def create_predictor(args, mode, logger):
config
.
set_trt_dynamic_shape_info
(
min_input_shape
,
max_input_shape
,
opt_input_shape
)
elif
args
.
use_xpu
:
config
.
enable_xpu
(
10
*
1024
*
1024
)
else
:
config
.
disable_gpu
()
if
hasattr
(
args
,
"cpu_threads"
):
...
...
@@ -630,7 +633,6 @@ def get_rotate_crop_image(img, points):
def
check_gpu
(
use_gpu
):
if
use_gpu
and
not
paddle
.
is_compiled_with_cuda
():
use_gpu
=
False
return
use_gpu
...
...
tools/program.py
浏览文件 @
a246ab94
...
...
@@ -128,20 +128,25 @@ def merge_config(config):
cur
=
cur
[
sub_key
]
def
check_
gpu
(
use_gpu
):
def
check_
device
(
use_gpu
,
use_xpu
=
False
):
"""
Log error and exit when set use_gpu=true in paddlepaddle
cpu version.
"""
err
=
"Config
use_gpu cannot be set as true while you ar
e "
\
"
using paddlepaddle cpu version
!
\n
Please try:
\n
"
\
"
\t
1. Install paddlepaddle
-gpu to run model on GPU
\n
"
\
"
\t
2. Set
use_gpu
as false in config file to run "
\
err
=
"Config
{} cannot be set as true while your paddl
e "
\
"
is not compiled with {}
!
\n
Please try:
\n
"
\
"
\t
1. Install paddlepaddle
to run model on {}
\n
"
\
"
\t
2. Set
{}
as false in config file to run "
\
"model on CPU"
try
:
if
use_gpu
and
use_xpu
:
print
(
"use_xpu and use_gpu can not both be ture."
)
if
use_gpu
and
not
paddle
.
is_compiled_with_cuda
():
print
(
err
)
print
(
err
.
format
(
"use_gpu"
,
"cuda"
,
"gpu"
,
"use_gpu"
))
sys
.
exit
(
1
)
if
use_xpu
and
not
paddle
.
device
.
is_compiled_with_xpu
():
print
(
err
.
format
(
"use_xpu"
,
"xpu"
,
"xpu"
,
"use_xpu"
))
sys
.
exit
(
1
)
except
Exception
as
e
:
pass
...
...
@@ -497,7 +502,7 @@ def preprocess(is_train=False):
# check if set use_gpu=True in paddlepaddle cpu version
use_gpu
=
config
[
'Global'
][
'use_gpu'
]
check_gpu
(
use_gpu
)
use_xpu
=
config
[
'Global'
].
get
(
'use_xpu'
,
False
)
alg
=
config
[
'Architecture'
][
'algorithm'
]
assert
alg
in
[
...
...
@@ -511,7 +516,13 @@ def preprocess(is_train=False):
windows_not_support_list
))
sys
.
exit
()
device
=
'gpu:{}'
.
format
(
dist
.
ParallelEnv
().
dev_id
)
if
use_gpu
else
'cpu'
if
use_xpu
:
device
=
'xpu:{0}'
.
format
(
os
.
getenv
(
'FLAGS_selected_xpus'
,
0
))
else
:
device
=
'gpu:{}'
.
format
(
dist
.
ParallelEnv
()
.
dev_id
)
if
use_gpu
else
'cpu'
check_device
(
use_gpu
,
use_xpu
)
device
=
paddle
.
set_device
(
device
)
config
[
'Global'
][
'distributed'
]
=
dist
.
get_world_size
()
!=
1
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录