Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
精巧构思
PaddleOCR
提交
22838d50
P
PaddleOCR
项目概览
精巧构思
/
PaddleOCR
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleOCR
通知
2
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
22838d50
编写于
9月 03, 2021
作者:
qq_25193841
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/dygraph' into dygraph
上级
fd62f278
03b7daa5
变更
10
展开全部
隐藏空白更改
内联
并排
Showing
10 changed file
with
259 addition
and
18 deletion
+259
-18
deploy/cpp_infer/CMakeLists.txt
deploy/cpp_infer/CMakeLists.txt
+3
-3
deploy/cpp_infer/external-cmake/auto-log.cmake
deploy/cpp_infer/external-cmake/auto-log.cmake
+9
-10
deploy/cpp_infer/src/main.cpp
deploy/cpp_infer/src/main.cpp
+1
-0
tests/compare_results.py
tests/compare_results.py
+133
-0
tests/results/det_results_gpu_fp32.txt
tests/results/det_results_gpu_fp32.txt
+49
-0
tests/results/det_results_gpu_trt_fp16.txt
tests/results/det_results_gpu_trt_fp16.txt
+49
-0
tools/export_model.py
tools/export_model.py
+3
-0
tools/infer/predict_det.py
tools/infer/predict_det.py
+10
-3
tools/infer/utility.py
tools/infer/utility.py
+1
-1
tools/infer_rec.py
tools/infer_rec.py
+1
-1
未找到文件。
deploy/cpp_infer/CMakeLists.txt
浏览文件 @
22838d50
project
(
ppocr CXX C
)
cmake_minimum_required
(
VERSION 3.14
)
option
(
WITH_MKL
"Compile demo with MKL/OpenBlas support, default use MKL."
ON
)
option
(
WITH_GPU
"Compile demo with GPU/CPU, default use CPU."
OFF
)
...
...
@@ -206,13 +207,12 @@ endif()
set
(
DEPS
${
DEPS
}
${
OpenCV_LIBS
}
)
include
(
ExternalProjec
t
)
include
(
FetchConten
t
)
include
(
external-cmake/auto-log.cmake
)
include_directories
(
${
CMAKE_CURRENT_BINARY_DIR
}
/autolog/src/extern_Autolog/auto_log
)
include_directories
(
${
FETCHCONTENT_BASE_DIR
}
/extern_autolog-src
)
AUX_SOURCE_DIRECTORY
(
./src SRCS
)
add_executable
(
${
DEMO_NAME
}
${
SRCS
}
)
target_link_libraries
(
${
DEMO_NAME
}
${
DEPS
}
)
if
(
WIN32 AND WITH_MKL
)
...
...
deploy/cpp_infer/external-cmake/auto-log.cmake
浏览文件 @
22838d50
find_package
(
Git REQUIRED
)
message
(
"
${
CMAKE_BUILD_TYPE
}
"
)
include
(
FetchContent
)
set
(
AUTOLOG_REPOSITORY https://github.com/LDOUBLEV/AutoLog.git
)
SET
(
AUTOLOG_INSTALL_DIR
${
CMAKE_CURRENT_BINARY_DIR
}
/install/Autolog
)
set
(
FETCHCONTENT_BASE_DIR
"
${
CMAKE_CURRENT_BINARY_DIR
}
/third-party"
)
ExternalProject_Add
(
extern_Autolog
PREFIX autolog
GIT_REPOSITORY
${
AUTOLOG_REPOSITORY
}
GIT_TAG main
DOWNLOAD_NO_EXTRACT True
INSTALL_COMMAND cmake -E echo
"Skipping install step."
FetchContent_Declare
(
extern_Autolog
PREFIX autolog
GIT_REPOSITORY https://github.com/LDOUBLEV/AutoLog.git
GIT_TAG main
)
FetchContent_MakeAvailable
(
extern_Autolog
)
deploy/cpp_infer/src/main.cpp
浏览文件 @
22838d50
...
...
@@ -35,6 +35,7 @@
#include <sys/stat.h>
#include <gflags/gflags.h>
#include "auto_log/autolog.h"
DEFINE_bool
(
use_gpu
,
false
,
"Infering with GPU or CPU."
);
DEFINE_int32
(
gpu_id
,
0
,
"Device id of GPU to execute."
);
...
...
tests/compare_results.py
0 → 100644
浏览文件 @
22838d50
import
numpy
as
np
import
os
import
subprocess
import
json
import
argparse
import
glob
def
init_args
():
parser
=
argparse
.
ArgumentParser
()
# params for testing assert allclose
parser
.
add_argument
(
"--atol"
,
type
=
float
,
default
=
1e-3
)
parser
.
add_argument
(
"--rtol"
,
type
=
float
,
default
=
1e-3
)
parser
.
add_argument
(
"--gt_file"
,
type
=
str
,
default
=
""
)
parser
.
add_argument
(
"--log_file"
,
type
=
str
,
default
=
""
)
parser
.
add_argument
(
"--precision"
,
type
=
str
,
default
=
"fp32"
)
return
parser
def
parse_args
():
parser
=
init_args
()
return
parser
.
parse_args
()
def
run_shell_command
(
cmd
):
p
=
subprocess
.
Popen
(
cmd
,
stdout
=
subprocess
.
PIPE
,
stderr
=
subprocess
.
PIPE
,
shell
=
True
)
out
,
err
=
p
.
communicate
()
if
p
.
returncode
==
0
:
return
out
.
decode
(
'utf-8'
)
else
:
return
None
def
parser_results_from_log_by_name
(
log_path
,
names_list
):
if
not
os
.
path
.
exists
(
log_path
):
raise
ValueError
(
"The log file {} does not exists!"
.
format
(
log_path
))
if
names_list
is
None
or
len
(
names_list
)
<
1
:
return
[]
parser_results
=
{}
for
name
in
names_list
:
cmd
=
"grep {} {}"
.
format
(
name
,
log_path
)
outs
=
run_shell_command
(
cmd
)
outs
=
outs
.
split
(
"
\n
"
)[
0
]
result
=
outs
.
split
(
"{}"
.
format
(
name
))[
-
1
]
result
=
json
.
loads
(
result
)
parser_results
[
name
]
=
result
return
parser_results
def
load_gt_from_file
(
gt_file
):
if
not
os
.
path
.
exists
(
gt_file
):
raise
ValueError
(
"The log file {} does not exists!"
.
format
(
gt_file
))
with
open
(
gt_file
,
'r'
)
as
f
:
data
=
f
.
readlines
()
f
.
close
()
parser_gt
=
{}
for
line
in
data
:
image_name
,
result
=
line
.
strip
(
"
\n
"
).
split
(
"
\t
"
)
result
=
json
.
loads
(
result
)
parser_gt
[
image_name
]
=
result
return
parser_gt
def
load_gt_from_txts
(
gt_file
):
gt_list
=
glob
.
glob
(
gt_file
)
gt_collection
=
{}
for
gt_f
in
gt_list
:
gt_dict
=
load_gt_from_file
(
gt_f
)
basename
=
os
.
path
.
basename
(
gt_f
)
if
"fp32"
in
basename
:
gt_collection
[
"fp32"
]
=
[
gt_dict
,
gt_f
]
elif
"fp16"
in
basename
:
gt_collection
[
"fp16"
]
=
[
gt_dict
,
gt_f
]
elif
"int8"
in
basename
:
gt_collection
[
"int8"
]
=
[
gt_dict
,
gt_f
]
else
:
continue
return
gt_collection
def
collect_predict_from_logs
(
log_path
,
key_list
):
log_list
=
glob
.
glob
(
log_path
)
pred_collection
=
{}
for
log_f
in
log_list
:
pred_dict
=
parser_results_from_log_by_name
(
log_f
,
key_list
)
key
=
os
.
path
.
basename
(
log_f
)
pred_collection
[
key
]
=
pred_dict
return
pred_collection
def
testing_assert_allclose
(
dict_x
,
dict_y
,
atol
=
1e-7
,
rtol
=
1e-7
):
for
k
in
dict_x
:
np
.
testing
.
assert_allclose
(
np
.
array
(
dict_x
[
k
]),
np
.
array
(
dict_y
[
k
]),
atol
=
atol
,
rtol
=
rtol
)
if
__name__
==
"__main__"
:
# Usage:
# python3.7 tests/compare_results.py --gt_file=./tests/results/*.txt --log_file=./tests/output/infer_*.log
args
=
parse_args
()
gt_collection
=
load_gt_from_txts
(
args
.
gt_file
)
key_list
=
gt_collection
[
"fp32"
][
0
].
keys
()
pred_collection
=
collect_predict_from_logs
(
args
.
log_file
,
key_list
)
for
filename
in
pred_collection
.
keys
():
if
"fp32"
in
filename
:
gt_dict
,
gt_filename
=
gt_collection
[
"fp32"
]
elif
"fp16"
in
filename
:
gt_dict
,
gt_filename
=
gt_collection
[
"fp16"
]
elif
"int8"
in
filename
:
gt_dict
,
gt_filename
=
gt_collection
[
"int8"
]
else
:
continue
pred_dict
=
pred_collection
[
filename
]
try
:
testing_assert_allclose
(
gt_dict
,
pred_dict
,
atol
=
args
.
atol
,
rtol
=
args
.
rtol
)
print
(
"Assert allclose passed! The results of {} and {} are consistent!"
.
format
(
filename
,
gt_filename
))
except
Exception
as
E
:
print
(
E
)
raise
ValueError
(
"The results of {} and the results of {} are inconsistent!"
.
format
(
filename
,
gt_filename
))
tests/results/det_results_gpu_fp32.txt
0 → 100644
浏览文件 @
22838d50
此差异已折叠。
点击以展开。
tests/results/det_results_gpu_trt_fp16.txt
0 → 100644
浏览文件 @
22838d50
此差异已折叠。
点击以展开。
tools/export_model.py
浏览文件 @
22838d50
...
...
@@ -93,6 +93,9 @@ def main():
for
key
in
config
[
"Architecture"
][
"Models"
]:
config
[
"Architecture"
][
"Models"
][
key
][
"Head"
][
"out_channels"
]
=
char_num
# just one final tensor needs to to exported for inference
config
[
"Architecture"
][
"Models"
][
key
][
"return_all_feats"
]
=
False
else
:
# base rec model
config
[
"Architecture"
][
"Head"
][
"out_channels"
]
=
char_num
model
=
build_model
(
config
[
"Architecture"
])
...
...
tools/infer/predict_det.py
浏览文件 @
22838d50
...
...
@@ -30,7 +30,7 @@ from ppocr.utils.logging import get_logger
from
ppocr.utils.utility
import
get_image_file_list
,
check_and_read_gif
from
ppocr.data
import
create_operators
,
transform
from
ppocr.postprocess
import
build_post_process
import
json
logger
=
get_logger
()
...
...
@@ -243,6 +243,7 @@ if __name__ == "__main__":
if
not
os
.
path
.
exists
(
draw_img_save
):
os
.
makedirs
(
draw_img_save
)
save_results
=
[]
for
image_file
in
image_file_list
:
img
,
flag
=
check_and_read_gif
(
image_file
)
if
not
flag
:
...
...
@@ -256,8 +257,11 @@ if __name__ == "__main__":
if
count
>
0
:
total_time
+=
elapse
count
+=
1
logger
.
info
(
"Predict time of {}: {}"
.
format
(
image_file
,
elapse
))
save_pred
=
os
.
path
.
basename
(
image_file
)
+
"
\t
"
+
str
(
json
.
dumps
(
np
.
array
(
dt_boxes
).
astype
(
np
.
int32
).
tolist
()))
+
"
\n
"
save_results
.
append
(
save_pred
)
logger
.
info
(
save_pred
)
logger
.
info
(
"The predict time of {}: {}"
.
format
(
image_file
,
elapse
))
src_im
=
utility
.
draw_text_det_res
(
dt_boxes
,
image_file
)
img_name_pure
=
os
.
path
.
split
(
image_file
)[
-
1
]
img_path
=
os
.
path
.
join
(
draw_img_save
,
...
...
@@ -265,5 +269,8 @@ if __name__ == "__main__":
cv2
.
imwrite
(
img_path
,
src_im
)
logger
.
info
(
"The visualized image saved in {}"
.
format
(
img_path
))
with
open
(
os
.
path
.
join
(
draw_img_save
,
"det_results.txt"
),
'w'
)
as
f
:
f
.
writelines
(
save_results
)
f
.
close
()
if
args
.
benchmark
:
text_detector
.
autolog
.
report
()
tools/infer/utility.py
浏览文件 @
22838d50
...
...
@@ -35,7 +35,7 @@ def init_args():
parser
.
add_argument
(
"--use_gpu"
,
type
=
str2bool
,
default
=
True
)
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
=
1
0
)
parser
.
add_argument
(
"--min_subgraph_size"
,
type
=
int
,
default
=
1
5
)
parser
.
add_argument
(
"--precision"
,
type
=
str
,
default
=
"fp32"
)
parser
.
add_argument
(
"--gpu_mem"
,
type
=
int
,
default
=
500
)
...
...
tools/infer_rec.py
浏览文件 @
22838d50
...
...
@@ -121,7 +121,7 @@ def main():
if
len
(
post_result
[
key
][
0
])
>=
2
:
rec_info
[
key
]
=
{
"label"
:
post_result
[
key
][
0
][
0
],
"score"
:
post_result
[
key
][
0
][
1
]
,
"score"
:
float
(
post_result
[
key
][
0
][
1
])
,
}
info
=
json
.
dumps
(
rec_info
)
else
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录