Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[Deps] make scipy as a runtime dependency #109

Merged
merged 2 commits into from
Mar 8, 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
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