Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix bug with detections offset and cover problem with additional test #611

Merged
merged 2 commits into from
Aug 27, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ def offset_detections(
parent_id_key: str = PARENT_ID_KEY,
detection_id_key: str = DETECTION_ID_KEY,
) -> sv.Detections:
if len(detections) == 0:
return detections
_detections = deepcopy(detections)
_detections.xyxy = np.array(
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,18 @@ def test_offset_detection() -> None:
assert result["detection_id"] != str(
detections["parent_id"][0]
), "New detection id (random) must be assigned"


def test_offset_detection_when_nothing_predicted() -> None:
# given
detections = sv.Detections.empty()

# when
result = offset_detections(
detections=detections,
offset_width=50,
offset_height=100,
)

# then
assert len(detections) == 0, "Expected empty detections in output"
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,42 @@ def run_function(self, a, b) -> BlockResult:
}, "Expected result of 3 + 5 + 6 (last value from init)"


def test_assembly_custom_python_block_when_init_not_provided() -> None:
# given
manifest = BlockManifest
run_function = """
def run_function(self, a, b) -> BlockResult:
return {"result": a + b + len(self._init_results)}
"""
python_code = PythonCode(
type="PythonCode",
run_function_code=run_function,
run_function_name="run_function",
imports=["import math"],
)

# when
workflow_block_class = assembly_custom_python_block(
block_type_name="some",
unique_identifier="unique-id",
manifest=manifest,
python_code=python_code,
)
workflow_block_instance = workflow_block_class()
execution_result = workflow_block_instance.run(a=3, b=5)

# then
assert (
workflow_block_class.get_init_parameters() == []
), "Expected no init parameters defined"
assert (
workflow_block_class.get_manifest() == BlockManifest
), "Expected manifest to be returned"
assert execution_result == {
"result": 8
}, "Expected result of 3 + 5 + 0 (last value from init)"


def test_assembly_custom_python_block_when_run_function_not_found() -> None:
# given
manifest = BlockManifest
Expand Down
Loading