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
ca14b865
Unverified
Commit
ca14b865
authored
Apr 27, 2021
by
Evezerest
Committed by
GitHub
Apr 27, 2021
Browse files
Merge branch 'dygraph' into dygraph
parents
09bcc3f3
64a3580f
Changes
33
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
114 additions
and
22 deletions
+114
-22
configs/e2e/e2e_r50_vd_pg.yml
configs/e2e/e2e_r50_vd_pg.yml
+7
-4
configs/rec/ch_ppocr_v2.0/rec_chinese_common_train_v2.0.yml
configs/rec/ch_ppocr_v2.0/rec_chinese_common_train_v2.0.yml
+1
-0
configs/rec/ch_ppocr_v2.0/rec_chinese_lite_train_v2.0.yml
configs/rec/ch_ppocr_v2.0/rec_chinese_lite_train_v2.0.yml
+1
-0
configs/rec/rec_icdar15_train.yml
configs/rec/rec_icdar15_train.yml
+1
-0
configs/rec/rec_mv3_none_bilstm_ctc.yml
configs/rec/rec_mv3_none_bilstm_ctc.yml
+1
-0
configs/rec/rec_mv3_none_none_ctc.yml
configs/rec/rec_mv3_none_none_ctc.yml
+1
-0
configs/rec/rec_mv3_tps_bilstm_att.yml
configs/rec/rec_mv3_tps_bilstm_att.yml
+1
-0
configs/rec/rec_mv3_tps_bilstm_ctc.yml
configs/rec/rec_mv3_tps_bilstm_ctc.yml
+1
-0
configs/rec/rec_r34_vd_none_bilstm_ctc.yml
configs/rec/rec_r34_vd_none_bilstm_ctc.yml
+1
-0
configs/rec/rec_r34_vd_none_none_ctc.yml
configs/rec/rec_r34_vd_none_none_ctc.yml
+1
-0
configs/rec/rec_r34_vd_tps_bilstm_att.yml
configs/rec/rec_r34_vd_tps_bilstm_att.yml
+1
-0
configs/rec/rec_r34_vd_tps_bilstm_ctc.yml
configs/rec/rec_r34_vd_tps_bilstm_ctc.yml
+1
-0
configs/rec/rec_r50_fpn_srn.yml
configs/rec/rec_r50_fpn_srn.yml
+1
-0
deploy/cpp_infer/include/postprocess_op.h
deploy/cpp_infer/include/postprocess_op.h
+1
-0
deploy/cpp_infer/src/postprocess_op.cpp
deploy/cpp_infer/src/postprocess_op.cpp
+35
-0
deploy/cpp_infer/src/preprocess_op.cpp
deploy/cpp_infer/src/preprocess_op.cpp
+3
-12
deploy/hubserving/ocr_cls/module.py
deploy/hubserving/ocr_cls/module.py
+18
-2
deploy/hubserving/ocr_det/module.py
deploy/hubserving/ocr_det/module.py
+19
-2
deploy/hubserving/ocr_det/params.py
deploy/hubserving/ocr_det/params.py
+1
-0
deploy/hubserving/ocr_rec/module.py
deploy/hubserving/ocr_rec/module.py
+18
-2
No files found.
configs/e2e/e2e_r50_vd_pg.yml
View file @
ca14b865
...
...
@@ -60,8 +60,10 @@ PostProcess:
name
:
PGPostProcess
score_thresh
:
0.5
mode
:
fast
# fast or slow two ways
Metric
:
name
:
E2EMetric
mode
:
A
# two ways for eval, A: label from txt, B: label from gt_mat
gt_mat_dir
:
./train_data/total_text/gt
# the dir of gt_mat
character_dict_path
:
ppocr/utils/ic15_dict.txt
main_indicator
:
f_score_e2e
...
...
@@ -70,13 +72,13 @@ Train:
dataset
:
name
:
PGDataSet
data_dir
:
./train_data/total_text/train
label_file_list
:
[
./train_data/total_text/train/
]
label_file_list
:
[
./train_data/total_text/train/
train.txt
]
ratio_list
:
[
1.0
]
transforms
:
-
DecodeImage
:
# load image
img_mode
:
BGR
channel_first
:
False
-
E2ELabelEncode
:
-
E2ELabelEncode
Train
:
-
PGProcessTrain
:
batch_size
:
14
# same as loader: batch_size_per_card
min_crop_size
:
24
...
...
@@ -94,11 +96,12 @@ Eval:
dataset
:
name
:
PGDataSet
data_dir
:
./train_data/total_text/test
label_file_list
:
[
./train_data/total_text/test/
]
label_file_list
:
[
./train_data/total_text/test/
test.txt
]
transforms
:
-
DecodeImage
:
# load image
img_mode
:
RGB
channel_first
:
False
-
E2ELabelEncodeTest
:
-
E2EResizeForTest
:
max_side_len
:
768
-
NormalizeImage
:
...
...
@@ -108,7 +111,7 @@ Eval:
order
:
'
hwc'
-
ToCHWImage
:
-
KeepKeys
:
keep_keys
:
[
'
image'
,
'
shape'
,
'
img_id'
]
keep_keys
:
[
'
image'
,
'
shape'
,
'
polys'
,
'
texts'
,
'
ignore_tags'
,
'
img_id'
]
loader
:
shuffle
:
False
drop_last
:
False
...
...
configs/rec/ch_ppocr_v2.0/rec_chinese_common_train_v2.0.yml
View file @
ca14b865
...
...
@@ -19,6 +19,7 @@ Global:
max_text_length
:
25
infer_mode
:
False
use_space_char
:
True
save_res_path
:
./output/rec/predicts_chinese_common_v2.0.txt
Optimizer
:
...
...
configs/rec/ch_ppocr_v2.0/rec_chinese_lite_train_v2.0.yml
View file @
ca14b865
...
...
@@ -19,6 +19,7 @@ Global:
max_text_length
:
25
infer_mode
:
False
use_space_char
:
True
save_res_path
:
./output/rec/predicts_chinese_lite_v2.0.txt
Optimizer
:
...
...
configs/rec/rec_icdar15_train.yml
View file @
ca14b865
...
...
@@ -19,6 +19,7 @@ Global:
max_text_length
:
25
infer_mode
:
False
use_space_char
:
False
save_res_path
:
./output/rec/predicts_ic15.txt
Optimizer
:
name
:
Adam
...
...
configs/rec/rec_mv3_none_bilstm_ctc.yml
View file @
ca14b865
...
...
@@ -19,6 +19,7 @@ Global:
max_text_length
:
25
infer_mode
:
False
use_space_char
:
False
save_res_path
:
./output/rec/predicts_mv3_none_bilstm_ctc.txt
Optimizer
:
name
:
Adam
...
...
configs/rec/rec_mv3_none_none_ctc.yml
View file @
ca14b865
...
...
@@ -19,6 +19,7 @@ Global:
max_text_length
:
25
infer_mode
:
False
use_space_char
:
False
save_res_path
:
./output/rec/predicts_mv3_none_none_ctc.txt
Optimizer
:
name
:
Adam
...
...
configs/rec/rec_mv3_tps_bilstm_att.yml
View file @
ca14b865
...
...
@@ -19,6 +19,7 @@ Global:
max_text_length
:
25
infer_mode
:
False
use_space_char
:
False
save_res_path
:
./output/rec/predicts_mv3_tps_bilstm_att.txt
Optimizer
:
...
...
configs/rec/rec_mv3_tps_bilstm_ctc.yml
View file @
ca14b865
...
...
@@ -19,6 +19,7 @@ Global:
max_text_length
:
25
infer_mode
:
False
use_space_char
:
False
save_res_path
:
./output/rec/predicts_mv3_tps_bilstm_ctc.txt
Optimizer
:
name
:
Adam
...
...
configs/rec/rec_r34_vd_none_bilstm_ctc.yml
View file @
ca14b865
...
...
@@ -19,6 +19,7 @@ Global:
max_text_length
:
25
infer_mode
:
False
use_space_char
:
False
save_res_path
:
./output/rec/predicts_r34_vd_none_bilstm_ctc.txt
Optimizer
:
name
:
Adam
...
...
configs/rec/rec_r34_vd_none_none_ctc.yml
View file @
ca14b865
...
...
@@ -19,6 +19,7 @@ Global:
max_text_length
:
25
infer_mode
:
False
use_space_char
:
False
save_res_path
:
./output/rec/predicts_r34_vd_none_none_ctc.txt
Optimizer
:
name
:
Adam
...
...
configs/rec/rec_r34_vd_tps_bilstm_att.yml
View file @
ca14b865
...
...
@@ -19,6 +19,7 @@ Global:
max_text_length
:
25
infer_mode
:
False
use_space_char
:
False
save_res_path
:
./output/rec/predicts_b3_rare_r34_none_gru.txt
Optimizer
:
...
...
configs/rec/rec_r34_vd_tps_bilstm_ctc.yml
View file @
ca14b865
...
...
@@ -19,6 +19,7 @@ Global:
max_text_length
:
25
infer_mode
:
False
use_space_char
:
False
save_res_path
:
./output/rec/predicts_r34_vd_tps_bilstm_ctc.txt
Optimizer
:
name
:
Adam
...
...
configs/rec/rec_r50_fpn_srn.yml
View file @
ca14b865
...
...
@@ -20,6 +20,7 @@ Global:
num_heads
:
8
infer_mode
:
False
use_space_char
:
False
save_res_path
:
./output/rec/predicts_srn.txt
Optimizer
:
...
...
deploy/cpp_infer/include/postprocess_op.h
View file @
ca14b865
...
...
@@ -51,6 +51,7 @@ public:
float
&
ssid
);
float
BoxScoreFast
(
std
::
vector
<
std
::
vector
<
float
>>
box_array
,
cv
::
Mat
pred
);
float
PolygonScoreAcc
(
std
::
vector
<
cv
::
Point
>
contour
,
cv
::
Mat
pred
);
std
::
vector
<
std
::
vector
<
std
::
vector
<
int
>>>
BoxesFromBitmap
(
const
cv
::
Mat
pred
,
const
cv
::
Mat
bitmap
,
...
...
deploy/cpp_infer/src/postprocess_op.cpp
View file @
ca14b865
...
...
@@ -159,6 +159,39 @@ std::vector<std::vector<float>> PostProcessor::GetMiniBoxes(cv::RotatedRect box,
return
array
;
}
float
PostProcessor
::
PolygonScoreAcc
(
std
::
vector
<
cv
::
Point
>
contour
,
cv
::
Mat
pred
){
int
width
=
pred
.
cols
;
int
height
=
pred
.
rows
;
std
::
vector
<
float
>
box_x
;
std
::
vector
<
float
>
box_y
;
for
(
int
i
=
0
;
i
<
contour
.
size
();
++
i
){
box_x
.
push_back
(
contour
[
i
].
x
);
box_y
.
push_back
(
contour
[
i
].
y
);
}
int
xmin
=
clamp
(
int
(
std
::
floor
(
*
(
std
::
min_element
(
box_x
.
begin
(),
box_x
.
end
())))),
0
,
width
-
1
);
int
xmax
=
clamp
(
int
(
std
::
ceil
(
*
(
std
::
max_element
(
box_x
.
begin
(),
box_x
.
end
())))),
0
,
width
-
1
);
int
ymin
=
clamp
(
int
(
std
::
floor
(
*
(
std
::
min_element
(
box_y
.
begin
(),
box_y
.
end
())))),
0
,
height
-
1
);
int
ymax
=
clamp
(
int
(
std
::
ceil
(
*
(
std
::
max_element
(
box_y
.
begin
(),
box_y
.
end
())))),
0
,
height
-
1
);
cv
::
Mat
mask
;
mask
=
cv
::
Mat
::
zeros
(
ymax
-
ymin
+
1
,
xmax
-
xmin
+
1
,
CV_8UC1
);
cv
::
Point
rook_point
[
contour
.
size
()];
for
(
int
i
=
0
;
i
<
contour
.
size
();
++
i
){
rook_point
[
i
]
=
cv
::
Point
(
int
(
box_x
[
i
])
-
xmin
,
int
(
box_y
[
i
])
-
ymin
);
}
const
cv
::
Point
*
ppt
[
1
]
=
{
rook_point
};
int
npt
[]
=
{
int
(
contour
.
size
())};
cv
::
fillPoly
(
mask
,
ppt
,
npt
,
1
,
cv
::
Scalar
(
1
));
cv
::
Mat
croppedImg
;
pred
(
cv
::
Rect
(
xmin
,
ymin
,
xmax
-
xmin
+
1
,
ymax
-
ymin
+
1
)).
copyTo
(
croppedImg
);
float
score
=
cv
::
mean
(
croppedImg
,
mask
)[
0
];
return
score
;
}
float
PostProcessor
::
BoxScoreFast
(
std
::
vector
<
std
::
vector
<
float
>>
box_array
,
cv
::
Mat
pred
)
{
auto
array
=
box_array
;
...
...
@@ -235,6 +268,8 @@ PostProcessor::BoxesFromBitmap(const cv::Mat pred, const cv::Mat bitmap,
float
score
;
score
=
BoxScoreFast
(
array
,
pred
);
/* compute using polygon*/
// score = PolygonScoreAcc(contours[_i], pred);
if
(
score
<
box_thresh
)
continue
;
...
...
deploy/cpp_infer/src/preprocess_op.cpp
100644 → 100755
View file @
ca14b865
...
...
@@ -77,19 +77,10 @@ void ResizeImgType0::Run(const cv::Mat &img, cv::Mat &resize_img,
int
resize_h
=
int
(
float
(
h
)
*
ratio
);
int
resize_w
=
int
(
float
(
w
)
*
ratio
);
if
(
resize_h
%
32
==
0
)
resize_h
=
resize_h
;
else
if
(
resize_h
/
32
<
1
+
1e-5
)
resize_h
=
32
;
else
resize_h
=
(
resize_h
/
32
)
*
32
;
resize_h
=
max
(
int
(
round
(
float
(
resize_h
)
/
32
)
*
32
),
32
);
resize_w
=
max
(
int
(
round
(
float
(
resize_w
)
/
32
)
*
32
),
32
);
if
(
resize_w
%
32
==
0
)
resize_w
=
resize_w
;
else
if
(
resize_w
/
32
<
1
+
1e-5
)
resize_w
=
32
;
else
resize_w
=
(
resize_w
/
32
)
*
32
;
if
(
!
use_tensorrt
)
{
cv
::
resize
(
img
,
resize_img
,
cv
::
Size
(
resize_w
,
resize_h
));
ratio_h
=
float
(
resize_h
)
/
float
(
h
);
...
...
deploy/hubserving/ocr_cls/module.py
View file @
ca14b865
...
...
@@ -6,6 +6,7 @@ from __future__ import print_function
import
os
import
sys
sys
.
path
.
insert
(
0
,
"."
)
import
copy
from
paddlehub.common.logger
import
logger
from
paddlehub.module.module
import
moduleinfo
,
runnable
,
serving
...
...
@@ -14,6 +15,8 @@ import paddlehub as hub
from
tools.infer.utility
import
base64_to_cv2
from
tools.infer.predict_cls
import
TextClassifier
from
tools.infer.utility
import
parse_args
from
deploy.hubserving.ocr_cls.params
import
read_params
@
moduleinfo
(
...
...
@@ -28,8 +31,7 @@ class OCRCls(hub.Module):
"""
initialize with the necessary elements
"""
from
ocr_cls.params
import
read_params
cfg
=
read_params
()
cfg
=
self
.
merge_configs
()
cfg
.
use_gpu
=
use_gpu
if
use_gpu
:
...
...
@@ -48,6 +50,20 @@ class OCRCls(hub.Module):
self
.
text_classifier
=
TextClassifier
(
cfg
)
def
merge_configs
(
self
,
):
# deafult cfg
backup_argv
=
copy
.
deepcopy
(
sys
.
argv
)
sys
.
argv
=
sys
.
argv
[:
1
]
cfg
=
parse_args
()
update_cfg_map
=
vars
(
read_params
())
for
key
in
update_cfg_map
:
cfg
.
__setattr__
(
key
,
update_cfg_map
[
key
])
sys
.
argv
=
copy
.
deepcopy
(
backup_argv
)
return
cfg
def
read_images
(
self
,
paths
=
[]):
images
=
[]
for
img_path
in
paths
:
...
...
deploy/hubserving/ocr_det/module.py
View file @
ca14b865
...
...
@@ -7,6 +7,8 @@ import os
import
sys
sys
.
path
.
insert
(
0
,
"."
)
import
copy
from
paddlehub.common.logger
import
logger
from
paddlehub.module.module
import
moduleinfo
,
runnable
,
serving
import
cv2
...
...
@@ -15,6 +17,8 @@ import paddlehub as hub
from
tools.infer.utility
import
base64_to_cv2
from
tools.infer.predict_det
import
TextDetector
from
tools.infer.utility
import
parse_args
from
deploy.hubserving.ocr_system.params
import
read_params
@
moduleinfo
(
...
...
@@ -29,8 +33,7 @@ class OCRDet(hub.Module):
"""
initialize with the necessary elements
"""
from
ocr_det.params
import
read_params
cfg
=
read_params
()
cfg
=
self
.
merge_configs
()
cfg
.
use_gpu
=
use_gpu
if
use_gpu
:
...
...
@@ -49,6 +52,20 @@ class OCRDet(hub.Module):
self
.
text_detector
=
TextDetector
(
cfg
)
def
merge_configs
(
self
,
):
# deafult cfg
backup_argv
=
copy
.
deepcopy
(
sys
.
argv
)
sys
.
argv
=
sys
.
argv
[:
1
]
cfg
=
parse_args
()
update_cfg_map
=
vars
(
read_params
())
for
key
in
update_cfg_map
:
cfg
.
__setattr__
(
key
,
update_cfg_map
[
key
])
sys
.
argv
=
copy
.
deepcopy
(
backup_argv
)
return
cfg
def
read_images
(
self
,
paths
=
[]):
images
=
[]
for
img_path
in
paths
:
...
...
deploy/hubserving/ocr_det/params.py
View file @
ca14b865
...
...
@@ -22,6 +22,7 @@ def read_params():
cfg
.
det_db_box_thresh
=
0.5
cfg
.
det_db_unclip_ratio
=
1.6
cfg
.
use_dilation
=
False
cfg
.
det_db_score_mode
=
"fast"
# #EAST parmas
# cfg.det_east_score_thresh = 0.8
...
...
deploy/hubserving/ocr_rec/module.py
View file @
ca14b865
...
...
@@ -6,6 +6,7 @@ from __future__ import print_function
import
os
import
sys
sys
.
path
.
insert
(
0
,
"."
)
import
copy
from
paddlehub.common.logger
import
logger
from
paddlehub.module.module
import
moduleinfo
,
runnable
,
serving
...
...
@@ -14,6 +15,8 @@ import paddlehub as hub
from
tools.infer.utility
import
base64_to_cv2
from
tools.infer.predict_rec
import
TextRecognizer
from
tools.infer.utility
import
parse_args
from
deploy.hubserving.ocr_rec.params
import
read_params
@
moduleinfo
(
...
...
@@ -28,8 +31,7 @@ class OCRRec(hub.Module):
"""
initialize with the necessary elements
"""
from
ocr_rec.params
import
read_params
cfg
=
read_params
()
cfg
=
self
.
merge_configs
()
cfg
.
use_gpu
=
use_gpu
if
use_gpu
:
...
...
@@ -48,6 +50,20 @@ class OCRRec(hub.Module):
self
.
text_recognizer
=
TextRecognizer
(
cfg
)
def
merge_configs
(
self
,
):
# deafult cfg
backup_argv
=
copy
.
deepcopy
(
sys
.
argv
)
sys
.
argv
=
sys
.
argv
[:
1
]
cfg
=
parse_args
()
update_cfg_map
=
vars
(
read_params
())
for
key
in
update_cfg_map
:
cfg
.
__setattr__
(
key
,
update_cfg_map
[
key
])
sys
.
argv
=
copy
.
deepcopy
(
backup_argv
)
return
cfg
def
read_images
(
self
,
paths
=
[]):
images
=
[]
for
img_path
in
paths
:
...
...
Prev
1
2
Next
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