🧪 reformatted tests
This commit is contained in:
parent
fc4bb27aa8
commit
4cd9f05fab
|
|
@ -448,7 +448,6 @@ class Detections:
|
|||
(self.xyxy[:, 1] + self.xyxy[:, 3]) / 2,
|
||||
]
|
||||
).transpose()
|
||||
|
||||
elif anchor == Position.CENTER_RIGHT:
|
||||
return np.array(
|
||||
[
|
||||
|
|
@ -456,15 +455,12 @@ class Detections:
|
|||
(self.xyxy[:, 1] + self.xyxy[:, 3]) / 2,
|
||||
]
|
||||
).transpose()
|
||||
|
||||
elif anchor == Position.BOTTOM_CENTER:
|
||||
return np.array(
|
||||
[(self.xyxy[:, 0] + self.xyxy[:, 2]) / 2, self.xyxy[:, 3]]
|
||||
).transpose()
|
||||
|
||||
elif anchor == Position.BOTTOM_LEFT:
|
||||
return np.array([self.xyxy[:, 0], self.xyxy[:, 3]]).transpose()
|
||||
|
||||
elif anchor == Position.BOTTOM_RIGHT:
|
||||
return np.array([self.xyxy[:, 2], self.xyxy[:, 3]]).transpose()
|
||||
elif anchor == Position.TOP_CENTER:
|
||||
|
|
|
|||
|
|
@ -172,5 +172,4 @@ def test_dataset_merge(
|
|||
) -> None:
|
||||
with exception:
|
||||
result = DetectionDataset.merge(dataset_list=dataset_list)
|
||||
print(result.images.keys())
|
||||
assert result == expected_result
|
||||
|
|
|
|||
|
|
@ -245,45 +245,83 @@ def test_merge(
|
|||
assert result == expected_result
|
||||
|
||||
|
||||
def test_get_anchor_coordinates() -> None:
|
||||
detections = mock_detections(
|
||||
xyxy=[
|
||||
[10, 10, 20, 20],
|
||||
[20, 20, 30, 30]
|
||||
]
|
||||
)
|
||||
result = detections.get_anchor_coordinates(Position.CENTER).tolist()
|
||||
expected_result = [[15, 15], [25, 25]]
|
||||
assert result == expected_result
|
||||
|
||||
result = detections.get_anchor_coordinates(Position.CENTER_LEFT).tolist()
|
||||
expected_result = [[10, 15], [20, 25]]
|
||||
assert result == expected_result
|
||||
|
||||
result = detections.get_anchor_coordinates(Position.CENTER_RIGHT).tolist()
|
||||
expected_result = [[20, 15], [30, 25]]
|
||||
assert result == expected_result
|
||||
|
||||
result = detections.get_anchor_coordinates(Position.TOP_CENTER).tolist()
|
||||
expected_result = [[15, 10], [25, 20]]
|
||||
assert result == expected_result
|
||||
|
||||
result = detections.get_anchor_coordinates(Position.TOP_LEFT).tolist()
|
||||
expected_result = [[10, 10], [20, 20]]
|
||||
assert result == expected_result
|
||||
|
||||
result = detections.get_anchor_coordinates(Position.TOP_RIGHT).tolist()
|
||||
expected_result = [[20, 10], [30, 20]]
|
||||
assert result == expected_result
|
||||
|
||||
result = detections.get_anchor_coordinates(Position.BOTTOM_CENTER).tolist()
|
||||
expected_result = [[15, 20], [25, 30]]
|
||||
assert result == expected_result
|
||||
|
||||
result = detections.get_anchor_coordinates(Position.BOTTOM_LEFT).tolist()
|
||||
expected_result = [[10, 20], [20, 30]]
|
||||
assert result == expected_result
|
||||
|
||||
result = detections.get_anchor_coordinates(Position.BOTTOM_RIGHT).tolist()
|
||||
expected_result = [[20, 20], [30, 30]]
|
||||
assert result == expected_result
|
||||
@pytest.mark.parametrize(
|
||||
'detections, anchor, expected_result, exception',
|
||||
[
|
||||
(
|
||||
Detections.empty(),
|
||||
Position.CENTER,
|
||||
np.empty((0, 2), dtype=np.float32),
|
||||
DoesNotRaise()
|
||||
), # empty detections
|
||||
(
|
||||
mock_detections(xyxy=[[10, 10, 20, 20]]),
|
||||
Position.CENTER,
|
||||
np.array([[15, 15]], dtype=np.float32),
|
||||
DoesNotRaise()
|
||||
), # single detection; center anchor
|
||||
(
|
||||
mock_detections(xyxy=[[10, 10, 20, 20], [20, 20, 30, 30]]),
|
||||
Position.CENTER,
|
||||
np.array([[15, 15], [25, 25]], dtype=np.float32),
|
||||
DoesNotRaise()
|
||||
), # two detections; center anchor
|
||||
(
|
||||
mock_detections(xyxy=[[10, 10, 20, 20], [20, 20, 30, 30]]),
|
||||
Position.CENTER_LEFT,
|
||||
np.array([[10, 15], [20, 25]], dtype=np.float32),
|
||||
DoesNotRaise()
|
||||
), # two detections; center left anchor
|
||||
(
|
||||
mock_detections(xyxy=[[10, 10, 20, 20], [20, 20, 30, 30]]),
|
||||
Position.CENTER_RIGHT,
|
||||
np.array([[20, 15], [30, 25]], dtype=np.float32),
|
||||
DoesNotRaise()
|
||||
), # two detections; center right anchor
|
||||
(
|
||||
mock_detections(xyxy=[[10, 10, 20, 20], [20, 20, 30, 30]]),
|
||||
Position.TOP_CENTER,
|
||||
np.array([[15, 10], [25, 20]], dtype=np.float32),
|
||||
DoesNotRaise()
|
||||
), # two detections; top center anchor
|
||||
(
|
||||
mock_detections(xyxy=[[10, 10, 20, 20], [20, 20, 30, 30]]),
|
||||
Position.TOP_LEFT,
|
||||
np.array([[10, 10], [20, 20]], dtype=np.float32),
|
||||
DoesNotRaise()
|
||||
), # two detections; top left anchor
|
||||
(
|
||||
mock_detections(xyxy=[[10, 10, 20, 20], [20, 20, 30, 30]]),
|
||||
Position.TOP_RIGHT,
|
||||
np.array([[20, 10], [30, 20]], dtype=np.float32),
|
||||
DoesNotRaise()
|
||||
), # two detections; top right anchor
|
||||
(
|
||||
mock_detections(xyxy=[[10, 10, 20, 20], [20, 20, 30, 30]]),
|
||||
Position.BOTTOM_CENTER,
|
||||
np.array([[15, 20], [25, 30]], dtype=np.float32),
|
||||
DoesNotRaise()
|
||||
), # two detections; bottom center anchor
|
||||
(
|
||||
mock_detections(xyxy=[[10, 10, 20, 20], [20, 20, 30, 30]]),
|
||||
Position.BOTTOM_LEFT,
|
||||
np.array([[10, 20], [20, 30]], dtype=np.float32),
|
||||
DoesNotRaise()
|
||||
), # two detections; bottom left anchor
|
||||
(
|
||||
mock_detections(xyxy=[[10, 10, 20, 20], [20, 20, 30, 30]]),
|
||||
Position.BOTTOM_RIGHT,
|
||||
np.array([[20, 20], [30, 30]], dtype=np.float32),
|
||||
DoesNotRaise()
|
||||
), # two detections; bottom right anchor
|
||||
]
|
||||
)
|
||||
def test_get_anchor_coordinates(
|
||||
detections: Detections,
|
||||
anchor: Position,
|
||||
expected_result: np.ndarray,
|
||||
exception: Exception
|
||||
) -> None:
|
||||
result = detections.get_anchor_coordinates(anchor)
|
||||
with exception:
|
||||
assert np.array_equal(result, expected_result)
|
||||
|
|
|
|||
Loading…
Reference in New Issue