Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleOCR
提交
3ebebae3
P
PaddleOCR
项目概览
PaddlePaddle
/
PaddleOCR
大约 1 年 前同步成功
通知
1528
Star
32962
Fork
6643
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
108
列表
看板
标记
里程碑
合并请求
7
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleOCR
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
108
Issue
108
列表
看板
标记
里程碑
合并请求
7
合并请求
7
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
3ebebae3
编写于
8月 22, 2020
作者:
littletomatodonkey
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
replace zero_copy_run to run for memory leak
上级
48848658
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
43 addition
and
32 deletion
+43
-32
deploy/cpp_infer/src/ocr_det.cpp
deploy/cpp_infer/src/ocr_det.cpp
+9
-7
deploy/cpp_infer/src/ocr_rec.cpp
deploy/cpp_infer/src/ocr_rec.cpp
+11
-7
tools/infer/predict_det.py
tools/infer/predict_det.py
+13
-10
tools/infer/predict_rec.py
tools/infer/predict_rec.py
+9
-6
tools/infer/utility.py
tools/infer/utility.py
+1
-2
未找到文件。
deploy/cpp_infer/src/ocr_det.cpp
浏览文件 @
3ebebae3
...
@@ -31,7 +31,8 @@ void DBDetector::LoadModel(const std::string &model_dir) {
...
@@ -31,7 +31,8 @@ void DBDetector::LoadModel(const std::string &model_dir) {
}
}
// false for zero copy tensor
// false for zero copy tensor
config
.
SwitchUseFeedFetchOps
(
false
);
// true for commom tensor
config
.
SwitchUseFeedFetchOps
(
true
);
// true for multiple input
// true for multiple input
config
.
SwitchSpecifyInputNames
(
true
);
config
.
SwitchSpecifyInputNames
(
true
);
...
@@ -59,12 +60,13 @@ void DBDetector::Run(cv::Mat &img,
...
@@ -59,12 +60,13 @@ void DBDetector::Run(cv::Mat &img,
std
::
vector
<
float
>
input
(
1
*
3
*
resize_img
.
rows
*
resize_img
.
cols
,
0.0
f
);
std
::
vector
<
float
>
input
(
1
*
3
*
resize_img
.
rows
*
resize_img
.
cols
,
0.0
f
);
this
->
permute_op_
.
Run
(
&
resize_img
,
input
.
data
());
this
->
permute_op_
.
Run
(
&
resize_img
,
input
.
data
());
auto
input_names
=
this
->
predictor_
->
GetInputNames
();
// Inference.
auto
input_t
=
this
->
predictor_
->
GetInputTensor
(
input_names
[
0
]);
paddle
::
PaddleTensor
input_t
;
input_t
->
Reshape
({
1
,
3
,
resize_img
.
rows
,
resize_img
.
cols
});
input_t
.
shape
=
{
1
,
3
,
resize_img
.
rows
,
resize_img
.
cols
};
input_t
->
copy_from_cpu
(
input
.
data
());
input_t
.
data
=
paddle
::
PaddleBuf
(
input
.
data
(),
input
.
size
()
*
sizeof
(
float
));
input_t
.
dtype
=
PaddleDType
::
FLOAT32
;
this
->
predictor_
->
ZeroCopyRun
();
std
::
vector
<
paddle
::
PaddleTensor
>
outputs
;
this
->
predictor_
->
Run
({
input_t
},
&
outputs
,
1
);
std
::
vector
<
float
>
out_data
;
std
::
vector
<
float
>
out_data
;
auto
output_names
=
this
->
predictor_
->
GetOutputNames
();
auto
output_names
=
this
->
predictor_
->
GetOutputNames
();
...
...
deploy/cpp_infer/src/ocr_rec.cpp
浏览文件 @
3ebebae3
...
@@ -39,18 +39,21 @@ void CRNNRecognizer::Run(std::vector<std::vector<std::vector<int>>> boxes,
...
@@ -39,18 +39,21 @@ void CRNNRecognizer::Run(std::vector<std::vector<std::vector<int>>> boxes,
this
->
permute_op_
.
Run
(
&
resize_img
,
input
.
data
());
this
->
permute_op_
.
Run
(
&
resize_img
,
input
.
data
());
auto
input_names
=
this
->
predictor_
->
GetInputNames
();
// Inference.
auto
input_t
=
this
->
predictor_
->
GetInputTensor
(
input_names
[
0
]);
paddle
::
PaddleTensor
input_t
;
input_t
->
Reshape
({
1
,
3
,
resize_img
.
rows
,
resize_img
.
cols
});
input_t
.
shape
=
{
1
,
3
,
resize_img
.
rows
,
resize_img
.
cols
};
input_t
->
copy_from_cpu
(
input
.
data
());
input_t
.
data
=
paddle
::
PaddleBuf
(
input
.
data
(),
input
.
size
()
*
sizeof
(
float
));
this
->
predictor_
->
ZeroCopyRun
();
input_t
.
dtype
=
PaddleDType
::
FLOAT32
;
std
::
vector
<
paddle
::
PaddleTensor
>
outputs
;
this
->
predictor_
->
Run
({
input_t
},
&
outputs
,
1
);
std
::
vector
<
int64_t
>
rec_idx
;
std
::
vector
<
int64_t
>
rec_idx
;
auto
output_names
=
this
->
predictor_
->
GetOutputNames
();
auto
output_names
=
this
->
predictor_
->
GetOutputNames
();
auto
output_t
=
this
->
predictor_
->
GetOutputTensor
(
output_names
[
0
]);
auto
output_t
=
this
->
predictor_
->
GetOutputTensor
(
output_names
[
0
]);
auto
rec_idx_lod
=
output_t
->
lod
();
auto
rec_idx_lod
=
output_t
->
lod
();
auto
shape_out
=
output_t
->
shape
();
auto
shape_out
=
output_t
->
shape
();
int
out_num
=
std
::
accumulate
(
shape_out
.
begin
(),
shape_out
.
end
(),
1
,
int
out_num
=
std
::
accumulate
(
shape_out
.
begin
(),
shape_out
.
end
(),
1
,
std
::
multiplies
<
int
>
());
std
::
multiplies
<
int
>
());
...
@@ -120,7 +123,8 @@ void CRNNRecognizer::LoadModel(const std::string &model_dir) {
...
@@ -120,7 +123,8 @@ void CRNNRecognizer::LoadModel(const std::string &model_dir) {
}
}
// false for zero copy tensor
// false for zero copy tensor
config
.
SwitchUseFeedFetchOps
(
false
);
// true for commom tensor
config
.
SwitchUseFeedFetchOps
(
true
);
// true for multiple input
// true for multiple input
config
.
SwitchSpecifyInputNames
(
true
);
config
.
SwitchSpecifyInputNames
(
true
);
...
...
tools/infer/predict_det.py
浏览文件 @
3ebebae3
...
@@ -17,22 +17,25 @@ __dir__ = os.path.dirname(os.path.abspath(__file__))
...
@@ -17,22 +17,25 @@ __dir__ = os.path.dirname(os.path.abspath(__file__))
sys
.
path
.
append
(
__dir__
)
sys
.
path
.
append
(
__dir__
)
sys
.
path
.
append
(
os
.
path
.
abspath
(
os
.
path
.
join
(
__dir__
,
'../..'
)))
sys
.
path
.
append
(
os
.
path
.
abspath
(
os
.
path
.
join
(
__dir__
,
'../..'
)))
import
cv2
import
copy
import
numpy
as
np
import
math
import
time
import
sys
import
paddle.fluid
as
fluid
import
tools.infer.utility
as
utility
import
tools.infer.utility
as
utility
from
ppocr.utils.utility
import
initial_logger
from
ppocr.utils.utility
import
initial_logger
logger
=
initial_logger
()
logger
=
initial_logger
()
from
ppocr.utils.utility
import
get_image_file_list
,
check_and_read_gif
from
ppocr.utils.utility
import
get_image_file_list
,
check_and_read_gif
import
cv2
from
ppocr.data.det.sast_process
import
SASTProcessTest
from
ppocr.data.det.sast_process
import
SASTProcessTest
from
ppocr.data.det.east_process
import
EASTProcessTest
from
ppocr.data.det.east_process
import
EASTProcessTest
from
ppocr.data.det.db_process
import
DBProcessTest
from
ppocr.data.det.db_process
import
DBProcessTest
from
ppocr.postprocess.db_postprocess
import
DBPostProcess
from
ppocr.postprocess.db_postprocess
import
DBPostProcess
from
ppocr.postprocess.east_postprocess
import
EASTPostPocess
from
ppocr.postprocess.east_postprocess
import
EASTPostPocess
from
ppocr.postprocess.sast_postprocess
import
SASTPostProcess
from
ppocr.postprocess.sast_postprocess
import
SASTPostProcess
import
copy
import
numpy
as
np
import
math
import
time
import
sys
class
TextDetector
(
object
):
class
TextDetector
(
object
):
...
@@ -135,8 +138,8 @@ class TextDetector(object):
...
@@ -135,8 +138,8 @@ class TextDetector(object):
return
None
,
0
return
None
,
0
im
=
im
.
copy
()
im
=
im
.
copy
()
starttime
=
time
.
time
()
starttime
=
time
.
time
()
self
.
input_tensor
.
copy_from_cpu
(
im
)
im
=
fluid
.
core
.
PaddleTensor
(
im
)
self
.
predictor
.
zero_copy_run
(
)
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
浏览文件 @
3ebebae3
...
@@ -17,15 +17,18 @@ __dir__ = os.path.dirname(os.path.abspath(__file__))
...
@@ -17,15 +17,18 @@ __dir__ = os.path.dirname(os.path.abspath(__file__))
sys
.
path
.
append
(
__dir__
)
sys
.
path
.
append
(
__dir__
)
sys
.
path
.
append
(
os
.
path
.
abspath
(
os
.
path
.
join
(
__dir__
,
'../..'
)))
sys
.
path
.
append
(
os
.
path
.
abspath
(
os
.
path
.
join
(
__dir__
,
'../..'
)))
import
tools.infer.utility
as
utility
from
ppocr.utils.utility
import
initial_logger
logger
=
initial_logger
()
from
ppocr.utils.utility
import
get_image_file_list
,
check_and_read_gif
import
cv2
import
cv2
import
copy
import
copy
import
numpy
as
np
import
numpy
as
np
import
math
import
math
import
time
import
time
import
paddle.fluid
as
fluid
import
tools.infer.utility
as
utility
from
ppocr.utils.utility
import
initial_logger
logger
=
initial_logger
()
from
ppocr.utils.utility
import
get_image_file_list
,
check_and_read_gif
from
ppocr.utils.character
import
CharacterOps
from
ppocr.utils.character
import
CharacterOps
...
@@ -102,8 +105,8 @@ class TextRecognizer(object):
...
@@ -102,8 +105,8 @@ 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
()
self
.
input_tensor
.
copy_from_cpu
(
norm_img_batch
)
norm_img_batch
=
fluid
.
core
.
PaddleTensor
(
norm_img_batch
)
self
.
predictor
.
zero_copy_run
(
)
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
浏览文件 @
3ebebae3
...
@@ -106,8 +106,7 @@ def create_predictor(args, mode):
...
@@ -106,8 +106,7 @@ def create_predictor(args, mode):
config
.
disable_glog_info
()
config
.
disable_glog_info
()
# use zero copy
# use zero copy
config
.
delete_pass
(
"conv_transpose_eltwiseadd_bn_fuse_pass"
)
config
.
switch_use_feed_fetch_ops
(
True
)
config
.
switch_use_feed_fetch_ops
(
False
)
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
])
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录