Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add nrtr dml distill loss #9968

Merged
merged 26 commits into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a201c3f
support min_area_rect crop
LDOUBLEV Oct 27, 2022
e53b2c5
add check_install
LDOUBLEV Nov 1, 2022
036f656
fix requirement.txt
LDOUBLEV Nov 1, 2022
d72f1ed
Merge branch 'dygraph' of https://github.com/PaddlePaddle/PaddleOCR i…
LDOUBLEV Nov 1, 2022
77eb065
fix check_install
LDOUBLEV Nov 2, 2022
501a677
add lanms-neo for drrg
LDOUBLEV Nov 2, 2022
1a79bfb
fix
LDOUBLEV Nov 4, 2022
bc7c761
fix doc
LDOUBLEV Nov 9, 2022
c478c59
fix
LDOUBLEV Dec 6, 2022
88ca1f1
fix conflict
LDOUBLEV Dec 8, 2022
e2a5cf9
Merge branch 'dygraph' of https://github.com/PaddlePaddle/PaddleOCR i…
LDOUBLEV Jan 30, 2023
ae41145
support set gpu_id when inference
LDOUBLEV Jan 30, 2023
92507b6
fix #8855
LDOUBLEV Jan 30, 2023
9b1b8c7
fix #8855
LDOUBLEV Jan 30, 2023
fbc1bc8
opt slim doc
LDOUBLEV Jan 31, 2023
9d71100
fix doc bug
LDOUBLEV Jan 31, 2023
a7c1cd4
Merge branch 'dygraph' of https://github.com/PaddlePaddle/PaddleOCR i…
LDOUBLEV Jan 31, 2023
204197e
Merge branch 'dygraph' of https://github.com/PaddlePaddle/PaddleOCR i…
LDOUBLEV Feb 16, 2023
b344e39
Merge branch 'dygraph' of https://github.com/PaddlePaddle/PaddleOCR i…
LDOUBLEV May 9, 2023
4c4e254
Merge branch 'dygraph' of https://github.com/PaddlePaddle/PaddleOCR i…
LDOUBLEV May 11, 2023
79533ff
add v4_rec_distill config
LDOUBLEV May 11, 2023
4e16b5d
delete debug
LDOUBLEV May 11, 2023
96244db
fix comment
LDOUBLEV May 15, 2023
6aefd22
fix comment
LDOUBLEV May 15, 2023
eb9b7c3
add dml nrtr distill loss
LDOUBLEV May 17, 2023
db89495
fix conflict
LDOUBLEV May 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add check_install
  • Loading branch information
LDOUBLEV committed Nov 1, 2022
commit e53b2c56fb9f5a650dcd72f43bcda710e4fa194f
4 changes: 2 additions & 2 deletions doc/doc_ch/algorithm_det_sast.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ python3 tools/export_model.py -c configs/det/det_r50_vd_sast_totaltext.yml -o Gl

```

SAST文本检测模型推理,需要设置参数`--det_algorithm="SAST"`,同时,还需要增加参数`--det_sast_polygon=True`,可以执行如下命令:
SAST文本检测模型推理,需要设置参数`--det_algorithm="SAST"`,同时,还需要增加参数`--det_box_type=poly`,可以执行如下命令:
```
python3 tools/infer/predict_det.py --det_algorithm="SAST" --image_dir="./doc/imgs_en/img623.jpg" --det_model_dir="./inference/det_sast_tt/" --det_sast_polygon=True
python3 tools/infer/predict_det.py --det_algorithm="SAST" --image_dir="./doc/imgs_en/img623.jpg" --det_model_dir="./inference/det_sast_tt/" --det_box_type='poly'
```
可视化文本检测结果默认保存到`./inference_results`文件夹里面,结果文件的名称前缀为'det_res'。结果示例如下:

Expand Down
4 changes: 2 additions & 2 deletions doc/doc_ch/inference_args.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ SAST算法相关参数如下
| :--: | :--: | :--: | :--: |
| det_sast_score_thresh | float | 0.5 | SAST后处理中的得分阈值 |
| det_sast_nms_thresh | float | 0.5 | SAST后处理中nms的阈值 |
| det_sast_polygon | bool | False | 是否多边形检测,弯曲文本场景(如Total-Text)设置为True |
| det_box_type | str | quad | 是否多边形检测,弯曲文本场景(如Total-Text)设置为'poly' |

PSE算法相关参数如下

Expand All @@ -79,7 +79,7 @@ PSE算法相关参数如下
| det_pse_thresh | float | 0.0 | 对输出图做二值化的阈值 |
| det_pse_box_thresh | float | 0.85 | 对box进行过滤的阈值,低于此阈值的丢弃 |
| det_pse_min_area | float | 16 | box的最小面积,低于此阈值的丢弃 |
| det_pse_box_type | str | "box" | 返回框的类型,box:四点坐标,poly: 弯曲文本的所有点坐标 |
| det_box_type | str | "quad" | 返回框的类型,quad:四点坐标,poly: 弯曲文本的所有点坐标 |
| det_pse_scale | int | 1 | 输入图像相对于进后处理的图的比例,如`640*640`的图像,网络输出为`160*160`,scale为2的情况下,进后处理的图片shape为`320*320`。这个值调大可以加快后处理速度,但是会带来精度的下降 |

* 文本识别模型相关
Expand Down
4 changes: 2 additions & 2 deletions doc/doc_en/algorithm_det_sast_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ First, convert the model saved in the SAST text detection training process into
python3 tools/export_model.py -c configs/det/det_r50_vd_sast_totaltext.yml -o Global.pretrained_model=./det_r50_vd_sast_totaltext_v2.0_train/best_accuracy Global.save_inference_dir=./inference/det_sast_tt
```

For SAST curved text detection model inference, you need to set the parameter `--det_algorithm="SAST"` and `--det_sast_polygon=True`, run the following command:
For SAST curved text detection model inference, you need to set the parameter `--det_algorithm="SAST"` and `--det_box_type=poly`, run the following command:

```
python3 tools/infer/predict_det.py --det_algorithm="SAST" --image_dir="./doc/imgs_en/img623.jpg" --det_model_dir="./inference/det_sast_tt/" --det_sast_polygon=True
python3 tools/infer/predict_det.py --det_algorithm="SAST" --image_dir="./doc/imgs_en/img623.jpg" --det_model_dir="./inference/det_sast_tt/" --det_box_type='poly'
```

The visualized text detection results are saved to the `./inference_results` folder by default, and the name of the result file is prefixed with 'det_res'. Examples of results are as follows:
Expand Down
4 changes: 2 additions & 2 deletions doc/doc_en/inference_args_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ The relevant parameters of the SAST algorithm are as follows
| :--: | :--: | :--: | :--: |
| det_sast_score_thresh | float | 0.5 | Score thresholds in SAST postprocess |
| det_sast_nms_thresh | float | 0.5 | Thresholding of nms in SAST postprocess |
| det_sast_polygon | bool | False | Whether polygon detection, curved text scene (such as Total-Text) is set to True |
| det_box_type | str | 'quad' | Whether polygon detection, curved text scene (such as Total-Text) is set to 'poly' |

The relevant parameters of the PSE algorithm are as follows

Expand All @@ -79,7 +79,7 @@ The relevant parameters of the PSE algorithm are as follows
| det_pse_thresh | float | 0.0 | Threshold for binarizing the output image |
| det_pse_box_thresh | float | 0.85 | Threshold for filtering boxes, below this threshold is discarded |
| det_pse_min_area | float | 16 | The minimum area of the box, below this threshold is discarded |
| det_pse_box_type | str | "box" | The type of the returned box, box: four point coordinates, poly: all point coordinates of the curved text |
| det_box_type | str | "quad" | The type of the returned box, quad: four point coordinates, poly: all point coordinates of the curved text |
| det_pse_scale | int | 1 | The ratio of the input image relative to the post-processed image, such as an image of `640*640`, the network output is `160*160`, and when the scale is 2, the shape of the post-processed image is `320*320`. Increasing this value can speed up the post-processing speed, but it will bring about a decrease in accuracy |

* Text recognition model related parameters
Expand Down
8 changes: 7 additions & 1 deletion ppocr/data/imaug/ct_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,13 @@
import paddle

import numpy as np
import Polygon as plg
from ppocr.utils.utility import check_install
try:
import Polygon as plg
except:
check_install("Polygon3")
import Polygon as plg

import scipy.io as scio

from PIL import Image
Expand Down
4 changes: 3 additions & 1 deletion ppocr/postprocess/east_postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import paddle

import os
from ppocr.utils.utility import check_install
import sys


Expand Down Expand Up @@ -78,11 +79,12 @@ def detect(self,
boxes[:, 8] = score_map[xy_text[:, 0], xy_text[:, 1]]

try:
check_install("lanms")
import lanms
boxes = lanms.merge_quadrangle_n9(boxes, nms_thresh)
except:
print(
'you should install lanms by pip3 install lanms-nova to speed up nms_locality'
'you should install lanms by pip3 install lanms to speed up nms_locality'
)
boxes = nms_locality(boxes.astype(np.float64), nms_thresh)
if boxes.shape[0] == 0:
Expand Down
6 changes: 5 additions & 1 deletion ppocr/utils/e2e_metric/Deteval.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
import json
import numpy as np
import scipy.io as io
import Polygon as plg
try:
import Polygon as plg
except:
check_install("Polygon3")
import Polygon as plg
from ppocr.utils.e2e_metric.polygon_fast import iod, area_of_intersection, area


Expand Down
22 changes: 22 additions & 0 deletions ppocr/utils/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
import random
import numpy as np
import paddle
import importlib.util
import sys
import subprocess


def print_dict(d, logger, delimiter=0):
Expand Down Expand Up @@ -131,6 +134,25 @@ def set_seed(seed=1024):
paddle.seed(seed)


def check_install(module_name):
spec = importlib.util.find_spec(module_name)
if spec is None:
print(f'Warnning! The {module_name} module is NOT installed')
print(
f'Try install {module_name} module automatically. You can also try to install manually.'
)
python = sys.executable
try:
subprocess.check_call(
[python, '-m', 'pip', 'install', 'requests'],
stdout=subprocess.DEVNULL)
print(f'The {module_name} module is now installed')
except subprocess.CalledProcessError as exc:
print(f"Install {module_name} failed, please install manually")
else:
print(f"{module_name} has been installed.")


class AverageMeter:
def __init__(self):
self.reset()
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@ premailer
openpyxl
attrdict
Polygon3
lanms-neo==1.0.2
PyMuPDF==1.19.0