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
cf03889b
"...composable_kernel_rocm.git" did not exist on "f5329887133aef6a690aa6dc5e6c0f92d000d8f8"
Commit
cf03889b
authored
Dec 19, 2020
by
weishengyu
Browse files
Merge
https://github.com/PaddlePaddle/PaddleOCR
into dygraph
parents
5a5017fe
011104e0
Changes
31
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
49 additions
and
29 deletions
+49
-29
doc/doc_en/angle_class_en.md
doc/doc_en/angle_class_en.md
+1
-1
doc/doc_en/detection_en.md
doc/doc_en/detection_en.md
+3
-3
doc/doc_en/inference_en.md
doc/doc_en/inference_en.md
+12
-4
doc/doc_en/recognition_en.md
doc/doc_en/recognition_en.md
+4
-4
doc/joinus.PNG
doc/joinus.PNG
+0
-0
paddleocr.py
paddleocr.py
+2
-2
setup.py
setup.py
+1
-1
tools/infer/predict_det.py
tools/infer/predict_det.py
+4
-0
tools/infer/utility.py
tools/infer/utility.py
+9
-3
tools/program.py
tools/program.py
+12
-10
tools/train.py
tools/train.py
+1
-1
No files found.
doc/doc_en/angle_class_en.md
View file @
cf03889b
...
...
@@ -119,7 +119,7 @@ Use `Global.infer_img` to specify the path of the predicted picture or folder, a
```
# Predict English results
python3 tools/infer_cls.py -c configs/cls/cls_mv3.yml -o Global.
checkpoints
={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words_en/word_10.png
python3 tools/infer_cls.py -c configs/cls/cls_mv3.yml -o Global.
pretrained_model
={path/to/weights}/best_accuracy
Global.load_static_weights=false
Global.infer_img=doc/imgs_words_en/word_10.png
```
Input image:
...
...
doc/doc_en/detection_en.md
View file @
cf03889b
...
...
@@ -113,16 +113,16 @@ python3 tools/eval.py -c configs/det/det_mv3_db.yml -o Global.checkpoints="{pat
Test the detection result on a single image:
```
shell
python3 tools/infer_det.py
-c
configs/det/det_mv3_db.yml
-o
Global.infer_img
=
"./doc/imgs_en/img_10.jpg"
Global.
checkpoints
=
"./output/det_db/best_accuracy"
python3 tools/infer_det.py
-c
configs/det/det_mv3_db.yml
-o
Global.infer_img
=
"./doc/imgs_en/img_10.jpg"
Global.
pretrained_model
=
"./output/det_db/best_accuracy"
Global.load_static_weights
=
false
```
When testing the DB model, adjust the post-processing threshold:
```
shell
python3 tools/infer_det.py
-c
configs/det/det_mv3_db.yml
-o
Global.infer_img
=
"./doc/imgs_en/img_10.jpg"
Global.
checkpoints
=
"./output/det_db/best_accuracy"
PostProcess.box_thresh
=
0.6 PostProcess.unclip_ratio
=
1.5
python3 tools/infer_det.py
-c
configs/det/det_mv3_db.yml
-o
Global.infer_img
=
"./doc/imgs_en/img_10.jpg"
Global.
pretrained_model
=
"./output/det_db/best_accuracy"
Global.load_static_weights
=
false
PostProcess.box_thresh
=
0.6 PostProcess.unclip_ratio
=
1.5
```
Test the detection result on all images in the folder:
```
shell
python3 tools/infer_det.py
-c
configs/det/det_mv3_db.yml
-o
Global.infer_img
=
"./doc/imgs_en/"
Global.
checkpoints
=
"./output/det_db/best_accuracy"
python3 tools/infer_det.py
-c
configs/det/det_mv3_db.yml
-o
Global.infer_img
=
"./doc/imgs_en/"
Global.
pretrained_model
=
"./output/det_db/best_accuracy"
Global.load_static_weights
=
false
```
doc/doc_en/inference_en.md
View file @
cf03889b
...
...
@@ -255,15 +255,18 @@ The following will introduce the lightweight Chinese recognition model inference
For lightweight Chinese recognition model inference, you can execute the following commands:
```
python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words/ch/word_4.jpg" --rec_model_dir="./inference/rec_crnn/"
# download CRNN text recognition inference model
wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_rec_infer.tar
tar xf ch_ppocr_mobile_v2.0_rec_infer.tar
python3 tools/infer/predict_rec.py --image_dir="./doc/imgs_words_en/word_10.png" --rec_model_dir="ch_ppocr_mobile_v2.0_rec_infer"
```


After executing the command, the prediction results (recognized text and score) of the above image will be printed on the screen.
```
bash
Predicts of ./doc/imgs_words
/ch
/word_
4.jpg:
(
'实力活力
'
, 0.98
458153
)
Predicts of ./doc/imgs_words
_en
/word_
10.png:
(
'PAIN
'
, 0.98
97658
)
```
<a
name=
"CTC-BASED_RECOGNITION"
></a>
...
...
@@ -339,7 +342,12 @@ For angle classification model inference, you can execute the following commands
```
python3 tools/infer/predict_cls.py --image_dir="./doc/imgs_words_en/word_10.png" --cls_model_dir="./inference/cls/"
```
```
# download text angle class inference model:
wget https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/ch_ppocr_mobile_v2.0_cls_infer.tar
tar xf ch_ppocr_mobile_v2.0_cls_infer.tar
python3 tools/infer/predict_cls.py --image_dir="./doc/imgs_words_en/word_10.png" --cls_model_dir="ch_ppocr_mobile_v2.0_cls_infer"
```

After executing the command, the prediction results (classification angle and score) of the above image will be printed on the screen.
...
...
doc/doc_en/recognition_en.md
View file @
cf03889b
...
...
@@ -317,11 +317,11 @@ Eval:
<a
name=
"EVALUATION"
></a>
### EVALUATION
The evaluation data
set can be
modified via
`configs/rec/rec_icdar15_reader.yml`
setting of
`label_file_path`
in EvalReader
.
The evaluation dataset can be
set by modifying the
`Eval.dataset.label_file_list`
field in the
`configs/rec/rec_icdar15_train.yml`
file
.
```
# GPU evaluation, Global.checkpoints is the weight to be tested
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_icdar15_
reader
.yml -o Global.checkpoints={path/to/weights}/best_accuracy
python3 -m paddle.distributed.launch --gpus '0' tools/eval.py -c configs/rec/rec_icdar15_
train
.yml -o Global.checkpoints={path/to/weights}/best_accuracy
```
<a
name=
"PREDICTION"
></a>
...
...
@@ -336,7 +336,7 @@ The default prediction picture is stored in `infer_img`, and the weight is speci
```
# Predict English results
python3 tools/infer_rec.py -c configs/rec/ch_ppocr_v2.0/rec_chinese_lite_train_v2.0.yml -o Global.
checkpoints
={path/to/weights}/best_accuracy
TestReader
.infer_img=doc/imgs_words/en/word_1.jpg
python3 tools/infer_rec.py -c configs/rec/ch_ppocr_v2.0/rec_chinese_lite_train_v2.0.yml -o Global.
pretrained_model
={path/to/weights}/best_accuracy
Global.load_static_weights=false Global
.infer_img=doc/imgs_words/en/word_1.jpg
```
Input image:
...
...
@@ -354,7 +354,7 @@ The configuration file used for prediction must be consistent with the training.
```
# Predict Chinese results
python3 tools/infer_rec.py -c configs/rec/ch_ppocr_v2.0/rec_chinese_lite_train_v2.0.yml -o Global.
checkpoints
={path/to/weights}/best_accuracy
TestReader
.infer_img=doc/imgs_words/ch/word_1.jpg
python3 tools/infer_rec.py -c configs/rec/ch_ppocr_v2.0/rec_chinese_lite_train_v2.0.yml -o Global.
pretrained_model
={path/to/weights}/best_accuracy
Global.load_static_weights=false Global
.infer_img=doc/imgs_words/ch/word_1.jpg
```
Input image:
...
...
doc/joinus.PNG
View replaced file @
5a5017fe
View file @
cf03889b
272 KB
|
W:
|
H:
212 KB
|
W:
|
H:
2-up
Swipe
Onion skin
paddleocr.py
View file @
cf03889b
...
...
@@ -262,8 +262,8 @@ class PaddleOCR(predict_system.TextSystem):
logger
.
error
(
'rec_algorithm must in {}'
.
format
(
SUPPORT_REC_MODEL
))
sys
.
exit
(
0
)
postprocess_params
.
rec_char_dict_path
=
Path
(
__file__
).
parent
/
postprocess_params
.
rec_char_dict_path
postprocess_params
.
rec_char_dict_path
=
str
(
Path
(
__file__
).
parent
/
postprocess_params
.
rec_char_dict_path
)
# init det_model and rec_model
super
().
__init__
(
postprocess_params
)
...
...
setup.py
View file @
cf03889b
...
...
@@ -32,7 +32,7 @@ setup(
package_dir
=
{
'paddleocr'
:
''
},
include_package_data
=
True
,
entry_points
=
{
"console_scripts"
:
[
"paddleocr= paddleocr.paddleocr:main"
]},
version
=
'2.0.
1
'
,
version
=
'2.0.
2
'
,
install_requires
=
requirements
,
license
=
'Apache License 2.0'
,
description
=
'Awesome OCR toolkits based on PaddlePaddle (8.6M ultra-lightweight pre-trained model, support training and deployment among server, mobile, embeded and IoT devices'
,
...
...
tools/infer/predict_det.py
View file @
cf03889b
...
...
@@ -35,6 +35,7 @@ logger = get_logger()
class
TextDetector
(
object
):
def
__init__
(
self
,
args
):
self
.
args
=
args
self
.
det_algorithm
=
args
.
det_algorithm
self
.
use_zero_copy_run
=
args
.
use_zero_copy_run
pre_process_list
=
[{
...
...
@@ -70,6 +71,9 @@ class TextDetector(object):
postprocess_params
[
"cover_thresh"
]
=
args
.
det_east_cover_thresh
postprocess_params
[
"nms_thresh"
]
=
args
.
det_east_nms_thresh
elif
self
.
det_algorithm
==
"SAST"
:
pre_process_list
[
0
]
=
{
'DetResizeForTest'
:
{
'resize_long'
:
args
.
det_limit_side_len
}
}
postprocess_params
[
'name'
]
=
'SASTPostProcess'
postprocess_params
[
"score_thresh"
]
=
args
.
det_sast_score_thresh
postprocess_params
[
"nms_thresh"
]
=
args
.
det_sast_nms_thresh
...
...
tools/infer/utility.py
View file @
cf03889b
...
...
@@ -33,6 +33,7 @@ def parse_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
(
"--use_fp16"
,
type
=
str2bool
,
default
=
False
)
parser
.
add_argument
(
"--gpu_mem"
,
type
=
int
,
default
=
8000
)
# params for text detector
...
...
@@ -46,7 +47,7 @@ def parse_args():
parser
.
add_argument
(
"--det_db_thresh"
,
type
=
float
,
default
=
0.3
)
parser
.
add_argument
(
"--det_db_box_thresh"
,
type
=
float
,
default
=
0.5
)
parser
.
add_argument
(
"--det_db_unclip_ratio"
,
type
=
float
,
default
=
1.6
)
parser
.
add_argument
(
"--max_batch_size"
,
type
=
int
,
default
=
10
)
# EAST parmas
parser
.
add_argument
(
"--det_east_score_thresh"
,
type
=
float
,
default
=
0.8
)
parser
.
add_argument
(
"--det_east_cover_thresh"
,
type
=
float
,
default
=
0.1
)
...
...
@@ -62,7 +63,7 @@ def parse_args():
parser
.
add_argument
(
"--rec_model_dir"
,
type
=
str
)
parser
.
add_argument
(
"--rec_image_shape"
,
type
=
str
,
default
=
"3, 32, 320"
)
parser
.
add_argument
(
"--rec_char_type"
,
type
=
str
,
default
=
'ch'
)
parser
.
add_argument
(
"--rec_batch_num"
,
type
=
int
,
default
=
6
)
parser
.
add_argument
(
"--rec_batch_num"
,
type
=
int
,
default
=
1
)
parser
.
add_argument
(
"--max_text_length"
,
type
=
int
,
default
=
25
)
parser
.
add_argument
(
"--rec_char_dict_path"
,
...
...
@@ -78,7 +79,7 @@ def parse_args():
parser
.
add_argument
(
"--cls_model_dir"
,
type
=
str
)
parser
.
add_argument
(
"--cls_image_shape"
,
type
=
str
,
default
=
"3, 48, 192"
)
parser
.
add_argument
(
"--label_list"
,
type
=
list
,
default
=
[
'0'
,
'180'
])
parser
.
add_argument
(
"--cls_batch_num"
,
type
=
int
,
default
=
30
)
parser
.
add_argument
(
"--cls_batch_num"
,
type
=
int
,
default
=
6
)
parser
.
add_argument
(
"--cls_thresh"
,
type
=
float
,
default
=
0.9
)
parser
.
add_argument
(
"--enable_mkldnn"
,
type
=
str2bool
,
default
=
False
)
...
...
@@ -113,6 +114,11 @@ def create_predictor(args, mode, logger):
if
args
.
use_gpu
:
config
.
enable_use_gpu
(
args
.
gpu_mem
,
0
)
if
args
.
use_tensorrt
:
config
.
enable_tensorrt_engine
(
precision_mode
=
AnalysisConfig
.
Precision
.
Half
if
args
.
use_fp16
else
AnalysisConfig
.
Precision
.
Float32
,
max_batch_size
=
args
.
max_batch_size
)
else
:
config
.
disable_gpu
()
config
.
set_cpu_math_library_num_threads
(
6
)
...
...
tools/program.py
View file @
cf03889b
...
...
@@ -332,7 +332,7 @@ def eval(model, valid_dataloader, post_process_class, eval_class):
return
metirc
def
preprocess
():
def
preprocess
(
is_train
=
False
):
FLAGS
=
ArgsParser
().
parse_args
()
config
=
load_config
(
FLAGS
.
config
)
merge_config
(
FLAGS
.
opt
)
...
...
@@ -350,15 +350,17 @@ def preprocess():
device
=
paddle
.
set_device
(
device
)
config
[
'Global'
][
'distributed'
]
=
dist
.
get_world_size
()
!=
1
# save_config
save_model_dir
=
config
[
'Global'
][
'save_model_dir'
]
os
.
makedirs
(
save_model_dir
,
exist_ok
=
True
)
with
open
(
os
.
path
.
join
(
save_model_dir
,
'config.yml'
),
'w'
)
as
f
:
yaml
.
dump
(
dict
(
config
),
f
,
default_flow_style
=
False
,
sort_keys
=
False
)
logger
=
get_logger
(
name
=
'root'
,
log_file
=
'{}/train.log'
.
format
(
save_model_dir
))
if
is_train
:
# save_config
save_model_dir
=
config
[
'Global'
][
'save_model_dir'
]
os
.
makedirs
(
save_model_dir
,
exist_ok
=
True
)
with
open
(
os
.
path
.
join
(
save_model_dir
,
'config.yml'
),
'w'
)
as
f
:
yaml
.
dump
(
dict
(
config
),
f
,
default_flow_style
=
False
,
sort_keys
=
False
)
log_file
=
'{}/train.log'
.
format
(
save_model_dir
)
else
:
log_file
=
None
logger
=
get_logger
(
name
=
'root'
,
log_file
=
log_file
)
if
config
[
'Global'
][
'use_visualdl'
]:
from
visualdl
import
LogWriter
vdl_writer_path
=
'{}/vdl/'
.
format
(
save_model_dir
)
...
...
tools/train.py
View file @
cf03889b
...
...
@@ -110,6 +110,6 @@ def test_reader(config, device, logger):
if
__name__
==
'__main__'
:
config
,
device
,
logger
,
vdl_writer
=
program
.
preprocess
()
config
,
device
,
logger
,
vdl_writer
=
program
.
preprocess
(
is_train
=
True
)
main
(
config
,
device
,
logger
,
vdl_writer
)
# test_reader(config, device, logger)
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