Skip to content

Commit

Permalink
[Enhance] Make scipy as a default dependency in runtime (open-mmlab#9186
Browse files Browse the repository at this point in the history
)
  • Loading branch information
BIGWangYuDong authored Nov 1, 2022
1 parent 13f8683 commit a81474a
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 17 deletions.
9 changes: 1 addition & 8 deletions mmdet/core/bbox/assigners/hungarian_assigner.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
# Copyright (c) OpenMMLab. All rights reserved.
import torch
from scipy.optimize import linear_sum_assignment

from ..builder import BBOX_ASSIGNERS
from ..match_costs import build_match_cost
from ..transforms import bbox_cxcywh_to_xyxy
from .assign_result import AssignResult
from .base_assigner import BaseAssigner

try:
from scipy.optimize import linear_sum_assignment
except ImportError:
linear_sum_assignment = None


@BBOX_ASSIGNERS.register_module()
class HungarianAssigner(BaseAssigner):
Expand Down Expand Up @@ -127,9 +123,6 @@ def assign(self,

# 3. do Hungarian matching on CPU using linear_sum_assignment
cost = cost.detach().cpu()
if linear_sum_assignment is None:
raise ImportError('Please run "pip install scipy" '
'to install scipy first.')
matched_row_inds, matched_col_inds = linear_sum_assignment(cost)
matched_row_inds = torch.from_numpy(matched_row_inds).to(
bbox_pred.device)
Expand Down
9 changes: 1 addition & 8 deletions mmdet/core/bbox/assigners/mask_hungarian_assigner.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
# Copyright (c) OpenMMLab. All rights reserved.
import torch
from scipy.optimize import linear_sum_assignment

from mmdet.core.bbox.builder import BBOX_ASSIGNERS
from mmdet.core.bbox.match_costs.builder import build_match_cost
from .assign_result import AssignResult
from .base_assigner import BaseAssigner

try:
from scipy.optimize import linear_sum_assignment
except ImportError:
linear_sum_assignment = None


@BBOX_ASSIGNERS.register_module()
class MaskHungarianAssigner(BaseAssigner):
Expand Down Expand Up @@ -112,9 +108,6 @@ def assign(self,

# 3. do Hungarian matching on CPU using linear_sum_assignment
cost = cost.detach().cpu()
if linear_sum_assignment is None:
raise ImportError('Please run "pip install scipy" '
'to install scipy first.')

matched_row_inds, matched_col_inds = linear_sum_assignment(cost)
matched_row_inds = torch.from_numpy(matched_row_inds).to(
Expand Down
1 change: 0 additions & 1 deletion requirements/optional.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
cityscapesscripts
imagecorruptions
scipy
sklearn
1 change: 1 addition & 0 deletions requirements/runtime.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
matplotlib
numpy
pycocotools
scipy
six
terminaltables

0 comments on commit a81474a

Please sign in to comment.