Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
wangsen
paddle_dbnet
Commits
0a011e56
Commit
0a011e56
authored
Aug 24, 2020
by
littletomatodonkey
Browse files
add python interface
parent
3ebebae3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
6 deletions
+21
-6
tools/infer/predict_det.py
tools/infer/predict_det.py
+7
-2
tools/infer/predict_rec.py
tools/infer/predict_rec.py
+7
-2
tools/infer/utility.py
tools/infer/utility.py
+7
-2
No files found.
tools/infer/predict_det.py
View file @
0a011e56
...
@@ -42,6 +42,7 @@ class TextDetector(object):
...
@@ -42,6 +42,7 @@ class TextDetector(object):
def
__init__
(
self
,
args
):
def
__init__
(
self
,
args
):
max_side_len
=
args
.
det_max_side_len
max_side_len
=
args
.
det_max_side_len
self
.
det_algorithm
=
args
.
det_algorithm
self
.
det_algorithm
=
args
.
det_algorithm
self
.
use_zero_copy_run
=
args
.
use_zero_copy_run
preprocess_params
=
{
'max_side_len'
:
max_side_len
}
preprocess_params
=
{
'max_side_len'
:
max_side_len
}
postprocess_params
=
{}
postprocess_params
=
{}
if
self
.
det_algorithm
==
"DB"
:
if
self
.
det_algorithm
==
"DB"
:
...
@@ -138,8 +139,12 @@ class TextDetector(object):
...
@@ -138,8 +139,12 @@ class TextDetector(object):
return
None
,
0
return
None
,
0
im
=
im
.
copy
()
im
=
im
.
copy
()
starttime
=
time
.
time
()
starttime
=
time
.
time
()
im
=
fluid
.
core
.
PaddleTensor
(
im
)
if
self
.
use_zero_copy_run
:
self
.
predictor
.
run
([
im
])
self
.
input_tensor
.
copy_from_cpu
(
im
)
self
.
predictor
.
zero_copy_run
()
else
:
im
=
fluid
.
core
.
PaddleTensor
(
im
)
self
.
predictor
.
run
([
im
])
outputs
=
[]
outputs
=
[]
for
output_tensor
in
self
.
output_tensors
:
for
output_tensor
in
self
.
output_tensors
:
output
=
output_tensor
.
copy_to_cpu
()
output
=
output_tensor
.
copy_to_cpu
()
...
...
tools/infer/predict_rec.py
View file @
0a011e56
...
@@ -40,6 +40,7 @@ class TextRecognizer(object):
...
@@ -40,6 +40,7 @@ class TextRecognizer(object):
self
.
character_type
=
args
.
rec_char_type
self
.
character_type
=
args
.
rec_char_type
self
.
rec_batch_num
=
args
.
rec_batch_num
self
.
rec_batch_num
=
args
.
rec_batch_num
self
.
rec_algorithm
=
args
.
rec_algorithm
self
.
rec_algorithm
=
args
.
rec_algorithm
self
.
use_zero_copy_run
=
args
.
use_zero_copy_run
char_ops_params
=
{
char_ops_params
=
{
"character_type"
:
args
.
rec_char_type
,
"character_type"
:
args
.
rec_char_type
,
"character_dict_path"
:
args
.
rec_char_dict_path
,
"character_dict_path"
:
args
.
rec_char_dict_path
,
...
@@ -105,8 +106,12 @@ class TextRecognizer(object):
...
@@ -105,8 +106,12 @@ class TextRecognizer(object):
norm_img_batch
=
np
.
concatenate
(
norm_img_batch
)
norm_img_batch
=
np
.
concatenate
(
norm_img_batch
)
norm_img_batch
=
norm_img_batch
.
copy
()
norm_img_batch
=
norm_img_batch
.
copy
()
starttime
=
time
.
time
()
starttime
=
time
.
time
()
norm_img_batch
=
fluid
.
core
.
PaddleTensor
(
norm_img_batch
)
if
self
.
use_zero_copy_run
:
self
.
predictor
.
run
([
norm_img_batch
])
self
.
input_tensor
.
copy_from_cpu
(
norm_img_batch
)
self
.
predictor
.
zero_copy_run
()
else
:
norm_img_batch
=
fluid
.
core
.
PaddleTensor
(
norm_img_batch
)
self
.
predictor
.
run
([
norm_img_batch
])
if
self
.
loss_type
==
"ctc"
:
if
self
.
loss_type
==
"ctc"
:
rec_idx_batch
=
self
.
output_tensors
[
0
].
copy_to_cpu
()
rec_idx_batch
=
self
.
output_tensors
[
0
].
copy_to_cpu
()
...
...
tools/infer/utility.py
View file @
0a011e56
...
@@ -71,6 +71,7 @@ def parse_args():
...
@@ -71,6 +71,7 @@ def parse_args():
default
=
"./ppocr/utils/ppocr_keys_v1.txt"
)
default
=
"./ppocr/utils/ppocr_keys_v1.txt"
)
parser
.
add_argument
(
"--use_space_char"
,
type
=
bool
,
default
=
True
)
parser
.
add_argument
(
"--use_space_char"
,
type
=
bool
,
default
=
True
)
parser
.
add_argument
(
"--enable_mkldnn"
,
type
=
bool
,
default
=
False
)
parser
.
add_argument
(
"--enable_mkldnn"
,
type
=
bool
,
default
=
False
)
parser
.
add_argument
(
"--use_zero_copy_run"
,
type
=
bool
,
default
=
False
)
return
parser
.
parse_args
()
return
parser
.
parse_args
()
...
@@ -105,8 +106,12 @@ def create_predictor(args, mode):
...
@@ -105,8 +106,12 @@ def create_predictor(args, mode):
#config.enable_memory_optim()
#config.enable_memory_optim()
config
.
disable_glog_info
()
config
.
disable_glog_info
()
# use zero copy
if
args
.
use_zero_copy_run
:
config
.
switch_use_feed_fetch_ops
(
True
)
config
.
delete_pass
(
"conv_transpose_eltwiseadd_bn_fuse_pass"
)
config
.
switch_use_feed_fetch_ops
(
False
)
else
:
config
.
switch_use_feed_fetch_ops
(
True
)
predictor
=
create_paddle_predictor
(
config
)
predictor
=
create_paddle_predictor
(
config
)
input_names
=
predictor
.
get_input_names
()
input_names
=
predictor
.
get_input_names
()
input_tensor
=
predictor
.
get_input_tensor
(
input_names
[
0
])
input_tensor
=
predictor
.
get_input_tensor
(
input_names
[
0
])
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment