Skip to content

Commit 47f5430

Browse files
authored
[Enhancement] Make lanms-neo optional (#1772)
* [Enhancement] Make lanms-neo optional * fix * rm
1 parent 465316f commit 47f5430

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

mmocr/models/textdet/heads/drrg_head.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
import torch
77
import torch.nn as nn
88
import torch.nn.functional as F
9-
from lanms import merge_quadrangle_n9 as la_nms
9+
10+
try:
11+
from lanms import merge_quadrangle_n9 as la_nms
12+
except ImportError:
13+
la_nms = None
1014
from mmcv.ops import RoIAlignRotated
1115
from mmengine.model import BaseModule
1216
from numpy import ndarray
@@ -838,6 +842,9 @@ def propose_comps_and_attribs(self, text_region_map: ndarray,
838842
self.comp_shrink_ratio,
839843
self.comp_w_h_ratio)
840844

845+
if la_nms is None:
846+
raise ImportError('lanms-neo is not installed, '
847+
'please run "pip install lanms-neo==1.0.2".')
841848
text_comps = la_nms(text_comps, self.nms_thr)
842849
text_comp_mask = np.zeros(mask_sz)
843850
text_comp_boxes = text_comps[:, :8].reshape(

mmocr/models/textdet/module_losses/drrg_module_loss.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
import cv2
55
import numpy as np
66
import torch
7-
from lanms import merge_quadrangle_n9 as la_nms
7+
8+
try:
9+
from lanms import merge_quadrangle_n9 as la_nms
10+
except ImportError:
11+
la_nms = None
812
from mmcv.image import imrescale
913
from mmdet.models.utils import multi_apply
1014
from numpy import ndarray
@@ -447,6 +451,9 @@ def _generate_comp_attribs(self, center_lines: List[ndarray],
447451

448452
score = np.ones((text_comps.shape[0], 1), dtype=np.float32)
449453
text_comps = np.hstack([text_comps, score])
454+
if la_nms is None:
455+
raise ImportError('lanms-neo is not installed, '
456+
'please run "pip install lanms-neo==1.0.2".')
450457
text_comps = la_nms(text_comps, self.text_comp_nms_thr)
451458

452459
if text_comps.shape[0] >= 1:

requirements/readthedocs.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
imgaug
22
kwarray
3-
lanms-neo==1.0.2
43
lmdb
54
matplotlib
65
mmcv>=2.0.0rc1

requirements/runtime.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
imgaug
2-
lanms-neo==1.0.2
32
lmdb
43
matplotlib
54
numpy

requirements/tests.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ interrogate
55
isort
66
# Note: used for kwarray.group_items, this may be ported to mmcv in the future.
77
kwarray
8+
lanms-neo==1.0.2
89
parameterized
910
pytest
1011
pytest-cov

0 commit comments

Comments
 (0)