Skip to content

Commit

Permalink
Add a test case when opencv is installed, enable both scenario (#1740)
Browse files Browse the repository at this point in the history
* Add a test case when opencv is installed, enable both scenario

Signed-off-by: tangy5 <[email protected]>

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Signed-off-by: tangy5 <[email protected]>
Co-authored-by: tangy5 <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Sep 5, 2024
1 parent 6b7d315 commit e31eaee
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions tests/unit/transform/test_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import importlib.util
import os
import tempfile
import unittest
Expand Down Expand Up @@ -56,14 +57,22 @@
(1, 6, 6),
]

FINDCONTOURSD_DATA = [
FINDCONTOURSD_DATA_NO_OPENCV = [
{"keys": "pred", "labels": "Other", "min_positive": 4, "min_poly_area": 1},
{
"pred": np.array([[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 0, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]]),
},
[[[3, 4], [1, 4], [0, 3], [0, 1], [1, 0], [3, 0], [4, 1], [4, 3], [3, 4]]],
]

FINDCONTOURSD_DATA_OPENCV = [
{"keys": "pred", "labels": "Other", "min_positive": 4, "min_poly_area": 1},
{
"pred": np.array([[0, 0, 0, 0, 0], [0, 1, 1, 1, 0], [0, 1, 0, 1, 0], [0, 1, 1, 1, 0], [0, 0, 0, 0, 0]]),
},
[[[1, 2], [2, 1], [3, 2], [2, 3]], [[1, 1], [1, 3], [3, 3], [3, 1]]],
]

DUMPIMAGEPREDICTION2DD_DATA = [
{
"image": np.random.rand(1, 3, 5, 5),
Expand Down Expand Up @@ -114,8 +123,12 @@ def test_result(self, args, input_data, expected_shape):
self.assertEqual(res["pred"].shape, expected_shape)


def is_opencv_installed():
return importlib.util.find_spec("cv2") is not None


class TestFindContoursd(unittest.TestCase):
@parameterized.expand([FINDCONTOURSD_DATA])
@parameterized.expand([FINDCONTOURSD_DATA_OPENCV if is_opencv_installed() else FINDCONTOURSD_DATA_NO_OPENCV])
def test_result(self, args, input_data, expected_output):
res = FindContoursd(**args)(input_data)
self.assertEqual(res["result"]["annotation"]["elements"][0]["contours"], expected_output)
Expand Down

0 comments on commit e31eaee

Please sign in to comment.