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

[Enhancement] Make lanms-neo optional #1772

Merged
merged 3 commits into from
Mar 10, 2023
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
9 changes: 8 additions & 1 deletion mmocr/models/textdet/heads/drrg_head.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import torch
import torch.nn as nn
import torch.nn.functional as F
from lanms import merge_quadrangle_n9 as la_nms

try:
from lanms import merge_quadrangle_n9 as la_nms
except ImportError:
la_nms = None
from mmcv.ops import RoIAlignRotated
from mmengine.model import BaseModule
from numpy import ndarray
Expand Down Expand Up @@ -838,6 +842,9 @@ def propose_comps_and_attribs(self, text_region_map: ndarray,
self.comp_shrink_ratio,
self.comp_w_h_ratio)

if la_nms is None:
raise ImportError('lanms-neo is not installed, '
'please run "pip install lanms-neo==1.0.2".')
text_comps = la_nms(text_comps, self.nms_thr)
text_comp_mask = np.zeros(mask_sz)
text_comp_boxes = text_comps[:, :8].reshape(
Expand Down
9 changes: 8 additions & 1 deletion mmocr/models/textdet/module_losses/drrg_module_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import cv2
import numpy as np
import torch
from lanms import merge_quadrangle_n9 as la_nms

try:
from lanms import merge_quadrangle_n9 as la_nms
except ImportError:
la_nms = None
from mmcv.image import imrescale
from mmdet.models.utils import multi_apply
from numpy import ndarray
Expand Down Expand Up @@ -447,6 +451,9 @@ def _generate_comp_attribs(self, center_lines: List[ndarray],

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

if text_comps.shape[0] >= 1:
Expand Down
1 change: 0 additions & 1 deletion requirements/readthedocs.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
imgaug
kwarray
lanms-neo==1.0.2
lmdb
matplotlib
mmcv>=2.0.0rc1
Expand Down
1 change: 0 additions & 1 deletion requirements/runtime.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
imgaug
lanms-neo==1.0.2
lmdb
matplotlib
numpy
Expand Down
1 change: 1 addition & 0 deletions requirements/tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ interrogate
isort
# Note: used for kwarray.group_items, this may be ported to mmcv in the future.
kwarray
lanms-neo==1.0.2
parameterized
pytest
pytest-cov
Expand Down