From 99415f1da14fa331b053ed383082d5b21104afc2 Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Fri, 11 Jul 2025 18:08:43 +0300 Subject: [PATCH] =?UTF-8?q?test:=20=F0=9F=A7=AA=20add=20parameterized=20te?= =?UTF-8?q?sts=20for=20from=5Fmoondream=20function=20in=20test=5Fvlm.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/detection/test_vlm.py | 101 +++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/test/detection/test_vlm.py b/test/detection/test_vlm.py index 2148ded9..bf578dd7 100644 --- a/test/detection/test_vlm.py +++ b/test/detection/test_vlm.py @@ -6,6 +6,7 @@ import pytest from supervision.detection.vlm import ( from_google_gemini, + from_moondream, from_paligemma, from_qwen_2_5_vl, ) @@ -375,3 +376,103 @@ def test_from_google_gemini() -> None: xyxy, np.array([[12.8, 4.8, 76.8, 52.8], [64.0, 24.0, 128.0, 72.0]]) ) np.testing.assert_array_equal(class_name, np.array(["cat", "dog"])) + + +@pytest.mark.parametrize( + "exception, result, resolution_wh, expected_results", + [ + ( + does_not_raise(), + {}, + (640, 480), + np.empty((0, 4)), + ), # empty dict + ( + does_not_raise(), + {"objects": []}, + (640, 480), + np.empty((0, 4)), + ), # empty objects list + ( + does_not_raise(), + {"objects": "not a list"}, + (640, 480), + np.empty((0, 4)), + ), # objects is not a list + ( + does_not_raise(), + { + "objects": [ + {"x_min": 0.1, "y_min": 0.2, "x_max": 0.3, "y_max": 0.4}, + ] + }, + (640, 480), + np.array([[64.0, 96.0, 192.0, 192.0]]), + ), # single box + ( + does_not_raise(), + { + "objects": [ + {"x_min": 0.1, "y_min": 0.2, "x_max": 0.3, "y_max": 0.4}, + {"x_min": 0.5, "y_min": 0.6, "x_max": 0.7, "y_max": 0.8}, + ] + }, + (640, 480), + np.array([[64.0, 96.0, 192.0, 192.0], [320.0, 288.0, 448.0, 384.0]]), + ), # multiple boxes + ( + does_not_raise(), + { + "objects": [ + {"x_min": 0.1, "y_min": 0.2}, # missing x_max, y_max + {"x_min": 0.5, "y_min": 0.6, "x_max": 0.7, "y_max": 0.8}, + ] + }, + (640, 480), + np.array([[320.0, 288.0, 448.0, 384.0]]), + ), # partial valid boxes + ( + does_not_raise(), + { + "objects": [ + {"x_min": 0.0, "y_min": 0.0, "x_max": 1.0, "y_max": 1.0}, + ] + }, + (1000, 800), + np.array([[0.0, 0.0, 1000.0, 800.0]]), + ), # full image box + ( + pytest.raises(ValueError), + { + "objects": [ + {"x_min": 0.1, "y_min": 0.2, "x_max": 0.3, "y_max": 0.4}, + ] + }, + (0, 480), + None, + ), # zero width -> ValueError + ( + pytest.raises(ValueError), + { + "objects": [ + {"x_min": 0.1, "y_min": 0.2, "x_max": 0.3, "y_max": 0.4}, + ] + }, + (640, -100), + None, + ), # negative height -> ValueError + ], +) +def test_from_moondream( + exception, + result: dict, + resolution_wh: Tuple[int, int], + expected_results, +) -> None: + with exception: + xyxy = from_moondream( + result=result, + resolution_wh=resolution_wh, + ) + if expected_results is not None: + np.testing.assert_array_equal(xyxy, expected_results)