Skip to content

Commit

Permalink
Make scipy as a runtime dependency (#109)
Browse files Browse the repository at this point in the history
* make scipy as a runtime dependency

* fix as comments
  • Loading branch information
C1rN09 authored Mar 8, 2023
1 parent 250c4bc commit 9f01f47
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
11 changes: 3 additions & 8 deletions mmeval/metrics/hmean_iou.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# Copyright (c) OpenMMLab. All rights reserved.
import numpy as np
from scipy import sparse
from typing import TYPE_CHECKING, Dict, List, Sequence, Tuple, Union

from mmeval.core import BaseMetric
from mmeval.metrics.utils import poly_intersection, poly_iou, polys2shapely
from mmeval.utils import try_import

if TYPE_CHECKING:
import scipy.sparse as scipy_sparse
import shapely.geometry as geometry
from shapely.geometry import Polygon
else:
scipy_sparse = try_import('scipy.sparse')
geometry = try_import('shapely.geometry')
if geometry is not None:
Polygon = geometry.Polygon
Expand Down Expand Up @@ -143,10 +142,6 @@ def __init__(
strategy: str = 'vanilla',
**kwargs,
) -> None:
if strategy == 'max_matching' and scipy_sparse is None:
raise RuntimeError(
'scipy is not installed, please run "pip install scipy" to use'
' HmeanIoUMetric with "max_matching" strategy.')
if geometry is None:
raise RuntimeError(
'shapely is not installed, please run "pip install shapely" to'
Expand Down Expand Up @@ -265,8 +260,8 @@ def _max_matching(self, iou_metric: np.ndarray) -> int:
Returns:
int: The hits by max matching policy.
"""
csr_matched_metric = scipy_sparse.csr_matrix(iou_metric)
matched_preds = scipy_sparse.csgraph.maximum_bipartite_matching(
csr_matched_metric = sparse.csr_matrix(iou_metric)
matched_preds = sparse.csgraph.maximum_bipartite_matching(
csr_matched_metric, perm_type='row')
# -1 denotes unmatched pred polygons
return np.sum(matched_preds != -1).item()
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 @@
opencv-python!=4.5.5.62,!=4.5.5.64
pycocotools
scipy
shapely
1 change: 1 addition & 0 deletions requirements/runtime.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
numpy
plum-dispatch<2.0.0
pyyaml
scipy

0 comments on commit 9f01f47

Please # to comment.