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 lambda function logic when all detections are filtered out #8931

Merged
merged 2 commits into from
Jan 14, 2025
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
@@ -0,0 +1,5 @@
### Fixed

- Fixed incorrect results being returned from lambda functions when all
detected shapes have labels that aren't mapped
(<https://github.com/cvat-ai/cvat/pull/8931>)
12 changes: 12 additions & 0 deletions cvat/apps/lambda_manager/tests/test_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,18 @@ def test_api_v2_lambda_functions_create_detector_without_mapping(self):
)
self.assertEqual(response.status_code, status.HTTP_200_OK)

def test_api_v2_lambda_functions_create_detector_all_shapes_unmapped(self):
data = {
"task": self.main_task["id"],
"frame": 0,
"mapping": {"person": {"name": "person"}},
}
response = self._post_request(
f"{LAMBDA_FUNCTIONS_PATH}/{id_function_detector}", self.admin, data
)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.json(), [])

def test_api_v2_lambda_functions_create_detector_without_task(self):
data = {
"frame": 0,
Expand Down
7 changes: 4 additions & 3 deletions cvat/apps/lambda_manager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,6 @@ def validate_attributes_mapping(attributes_mapping, model_attributes, db_attribu

response = self.gateway.invoke(self, payload)

response_filtered = []

def check_attr_value(value, db_attr):
if db_attr is None:
return False
Expand Down Expand Up @@ -509,6 +507,8 @@ def transform_attributes(input_attributes, attr_mapping, db_attributes):
return attributes

if self.kind == FunctionKind.DETECTOR:
response_filtered = []

for item in response:
item_label = item["label"]
if item_label not in mapping:
Expand All @@ -534,7 +534,8 @@ def transform_attributes(input_attributes, attr_mapping, db_attributes):
db_label.attributespec_set.values(),
)
response_filtered.append(item)
response = response_filtered

response = response_filtered

return response

Expand Down
Loading