test: 🧪 re-add parameterized tests for from_moondream function
This commit is contained in:
parent
eb330ac1c1
commit
3218da8cbd
|
|
@ -1135,10 +1135,7 @@ class Detections:
|
|||
|
||||
return cls(xyxy=xyxy, mask=mask, data=data)
|
||||
|
||||
if (
|
||||
vlm == VLM.GOOGLE_GEMINI_2_0
|
||||
or vlm == VLM.GOOGLE_GEMINI_2_5
|
||||
):
|
||||
if vlm == VLM.GOOGLE_GEMINI_2_0 or vlm == VLM.GOOGLE_GEMINI_2_5:
|
||||
xyxy, class_id, class_name = from_google_gemini(result, **kwargs)
|
||||
data = {CLASS_NAME_DATA_FIELD: class_name}
|
||||
return cls(xyxy=xyxy, class_id=class_id, data=data)
|
||||
|
|
|
|||
|
|
@ -427,7 +427,6 @@ def from_google_gemini(
|
|||
return xyxy, class_id, class_name
|
||||
|
||||
|
||||
|
||||
def from_moondream(
|
||||
result: dict,
|
||||
resolution_wh: Tuple[int, int],
|
||||
|
|
|
|||
|
|
@ -497,3 +497,103 @@ def test_from_google_gemini(
|
|||
np.testing.assert_array_equal(xyxy, expected_results[0])
|
||||
np.testing.assert_array_equal(class_id, expected_results[1])
|
||||
np.testing.assert_array_equal(class_name, expected_results[2])
|
||||
|
||||
|
||||
@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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue