Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support other devices in ppocr #13197

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion paddleocr.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _import_file(module_name, file_path, make_importable=False):
is_link,
confirm_model_dir_url,
)
from tools.infer.utility import draw_ocr, str2bool, check_gpu
from tools.infer.utility import draw_ocr, str2bool, check_gpu, check_xpu, check_npu, check_mlu
from ppstructure.utility import init_args, draw_structure_result
from ppstructure.predict_system import StructureSystem, save_structure_res, to_excel

Expand Down Expand Up @@ -619,6 +619,9 @@ def __init__(self, **kwargs):
SUPPORT_OCR_MODEL_VERSION, params.ocr_version
)
params.use_gpu = check_gpu(params.use_gpu)
params.use_xpu = check_xpu(params.use_xpu)
params.use_npu = check_npu(params.use_npu)
params.use_mlu = check_mlu(params.use_mlu)

if not params.show_log:
logger.setLevel(logging.INFO)
Expand Down
20 changes: 20 additions & 0 deletions tools/infer/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,26 @@ def check_gpu(use_gpu):
use_gpu = False
return use_gpu

def check_xpu(use_xpu):
if use_xpu and (
not paddle.is_compiled_with_xpu() or paddle.device.get_device() == "cpu"
):
use_xpu = False
return use_xpu

def check_npu(use_npu):
if use_npu and (
not paddle.is_compiled_with_custom_device("npu") or paddle.device.get_device() == "cpu"
):
use_npu = False
return use_npu

def check_mlu(use_mlu):
if use_mlu and (
not paddle.is_compiled_with_custom_device("mlu") or paddle.device.get_device() == "cpu"
):
use_mlu = False
return use_mlu

if __name__ == "__main__":
pass
Loading