Skip to content

修改 lanms 包安装的判定条件 #740

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

Merged
merged 8 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import platform
import sys

import cv2
Expand All @@ -14,10 +13,7 @@
try:
from lanms import merge_quadrangle_n9
except ImportError:
if platform.system() == "Windows":
from mindocr.postprocess.nms_py.lanms_py import merge_quadrangle_n9
else:
raise ImportError("can not import lanms or lanms_win")
from mindocr.postprocess.nms_py.lanms_py import merge_quadrangle_n9

__all__ = ["EASTPostprocess"]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import platform
import sys
from typing import Tuple

Expand All @@ -14,10 +13,7 @@
try:
from lanms import merge_quadrangle_n9
except ImportError:
if platform.system() == "Windows":
from mindocr.postprocess.nms_py.lanms_py import merge_quadrangle_n9
else:
raise ImportError("can not import lanms or lanms_win")
from mindocr.postprocess.nms_py.lanms_py import merge_quadrangle_n9

__all__ = ["SASTPostprocess"]

Expand Down
6 changes: 1 addition & 5 deletions mindocr/postprocess/det_east_postprocess.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import math
import platform

import numpy as np

Expand All @@ -10,10 +9,7 @@
try:
from lanms import merge_quadrangle_n9
except ImportError:
if platform.system() == "Windows":
from .nms_py.lanms_py import merge_quadrangle_n9
else:
raise ImportError("can not import lanms or lanms_win")
from .nms_py.lanms_py import merge_quadrangle_n9

__all__ = ["EASTPostprocess"]

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ PyYAML>=6.0
xml-python>=0.4.3
packaging>=23.1
Cython
lanms>=1.0.2; sys_platform == 'linux'
lanms>=1.0.2; python_version <= '3.10' and sys_platform == 'linux'
sentencepiece>=0.1.99
huggingface_hub>=0.16.4
seqeval>=1.2.2
Expand Down
1 change: 1 addition & 0 deletions tests/ut/lanms_test_jsons/test1.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions tests/ut/lanms_test_jsons/test2.json

Large diffs are not rendered by default.

23 changes: 21 additions & 2 deletions tests/ut/test_lanms_py.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import json
import os

import numpy as np

from mindocr.postprocess.nms_py.lanms_py import calculate_iou, merge_quadrangle_n9, standard_nms, weighted_merge
Expand All @@ -6,6 +9,15 @@
box2 = np.array([8, 10, 8, 50, 30, 50, 30, 10, 0.7])
box3 = np.array([9, 10, 9, 60, 30, 60, 30, 10, 1.1])

origin_boxes_test = []
expect_processed_boxes_test = []
lanms_test_jsons_path = os.path.join("tests/ut/lanms_test_jsons")
for file in os.listdir(lanms_test_jsons_path):
with open(os.path.join(lanms_test_jsons_path, file)) as f:
data = json.loads(f.readline())
origin_boxes_test.append(np.array(data["origin_boxes"]))
expect_processed_boxes_test.append(sorted(np.array(data["processed_boxes"]), key=lambda x: x[0]))


class TestLanmsPy:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议为类以及函数添加适当的文档,解释具体的功能与参数

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议为类以及函数添加适当的文档,解释具体的功能与参数

本部分代码较短,变量名称已经覆盖意义,多余的注释意义不大。

def test_calculate_iou(self):
Expand All @@ -16,8 +28,15 @@ def test_weighted_merge(self):
assert np.allclose(weighted_merge(box1, box2), expect_result, rtol=1e-2) is True

def test_standard_nms(self):
assert np.allclose(standard_nms([box2, box3], 0.5), box3, 1e-5)
assert np.allclose(standard_nms([box2, box3], 0.5), box3, 1e-5) is True

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议添加断言错误的提示消息,以便在断言失败时方便问题定位

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议添加断言错误的提示消息,以便在断言失败时方便问题定位

同上

def test_lanms(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

希望测试方法名清晰地描述它们的功能,如test_standard_nms、test_calculate_iou描述都是清晰的,但 test_lanms 稍显笼统,不便明确含义,建议可以更具体一些(如 test_merge_quadrangle_n9_with_multiple_boxes)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

希望测试方法名清晰地描述它们的功能,如test_standard_nms、test_calculate_iou描述都是清晰的,但 test_lanms 稍显笼统,不便明确含义,建议可以更具体一些(如 test_merge_quadrangle_n9_with_multiple_boxes)

lanms 是完整的算法。这个是 E2E 的测试。

expect_result = np.array([[8.611, 10, 8.611, 56.11, 30, 56.11, 30, 10, 1.8], [0, 0, 0, 20, 10, 20, 10, 0, 0.8]])
assert np.allclose(merge_quadrangle_n9([box1, box2, box3]), expect_result, 1e-2)
assert np.allclose(merge_quadrangle_n9([box1, box2, box3]), expect_result, 1e-2) is True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np.allclose 可直接返回比较结果,无需使用 is True

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

np.allclose 可直接返回比较结果,无需使用 is True

是的,之后统一清理小问题。


def test_real_situations(self):
real_results = []
for origin_box_test in origin_boxes_test:
real_results.append(sorted(merge_quadrangle_n9(origin_box_test), key=lambda x: x[0]))
for i, real_result in enumerate(real_results):
assert np.allclose(real_result, expect_processed_boxes_test[i], 1e-2) is True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议添加断言错误的提示消息,以便在断言失败时方便问题定位

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议添加断言错误的提示消息,以便在断言失败时方便问题定位

测试内容在函数名称已经写明。

Loading