Skip to content

Commit

Permalink
Fix lambda function logic when all detections are filtered out
Browse files Browse the repository at this point in the history
Currently, if all detected shapes have labels that aren't mapped, then the
mapping is not applied at all.
  • Loading branch information
SpecLad committed Jan 13, 2025
1 parent 42bc345 commit db24c1d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
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

0 comments on commit db24c1d

Please sign in to comment.