From fec040db35eb5f69694cded87e2c0ba8ebb20199 Mon Sep 17 00:00:00 2001 From: Roman Donchenko Date: Thu, 6 Feb 2025 15:17:52 +0200 Subject: [PATCH] Use `any` as the default function label type (#9050) Currently, the default is `unknown`, but allowing `unknown` as a function label type value creates some complications. * The sets of allowed label types of a task and of a function are not the same, so we have to use different enums to represent them. * `any` and `unknown` have similar meanings, and it's not clear what the difference between them is unless you search the code (AFAIK it's not documented anywhere). The sole benefit of having a separate `unknown` label type seems to be that function labels of type `any` are only allowed to be mapped to task labels of type `any`, while function labels of type `unknown` can be mapped to task labels of any type. But it doesn't seem like a useful distinction. Functions with both `unknown` and `any` label types can produce any shape types, so if we allow one of them, it makes sense to also allow the other. In addition, functions that can produce _multiple_ shape types for a single label are probably going to be rare, so I think it's reasonable to assume that a function with an `any`-typed label will still produce a single shape type and therefore can be mapped to a label with a specific type (although the user is responsible for ensuring that the types actually match). To sum up, I don't think the additional complexity introduced by the `unknown` type is worth it. So let's remove it and use `any` instead. This PR keeps some `unknown`-related logic in the UI, since there's some code in the Enterprise backend that also uses `unknown` as a label type. If this patch is accepted, I'll replace those uses with `any` too, then go back and remove the remaining logic here. --- changelog.d/20250204_183545_roman_unknown_any.md | 5 +++++ cvat-ui/src/components/model-runner-modal/labels-mapper.tsx | 2 +- cvat/apps/lambda_manager/views.py | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 changelog.d/20250204_183545_roman_unknown_any.md diff --git a/changelog.d/20250204_183545_roman_unknown_any.md b/changelog.d/20250204_183545_roman_unknown_any.md new file mode 100644 index 000000000000..c7a51a7e48f3 --- /dev/null +++ b/changelog.d/20250204_183545_roman_unknown_any.md @@ -0,0 +1,5 @@ +### Changed + +- When invoking Nuclio functions, labels of type `any` can now be mapped to + labels of all types except `skeleton` + () diff --git a/cvat-ui/src/components/model-runner-modal/labels-mapper.tsx b/cvat-ui/src/components/model-runner-modal/labels-mapper.tsx index 29098e158cb3..551dc3f08dfb 100644 --- a/cvat-ui/src/components/model-runner-modal/labels-mapper.tsx +++ b/cvat-ui/src/components/model-runner-modal/labels-mapper.tsx @@ -39,7 +39,7 @@ function labelsCompatible(modelLabel: LabelInterface, jobLabel: LabelInterface): const compatibleTypes = [[LabelType.MASK, LabelType.POLYGON]]; return modelLabelType === jobLabelType || (jobLabelType === 'any' && modelLabelType !== LabelType.SKELETON) || - (modelLabelType === 'unknown' && jobLabelType !== LabelType.SKELETON) || // legacy support + ((modelLabelType === 'any' || modelLabelType === 'unknown') && jobLabelType !== LabelType.SKELETON) || // legacy support compatibleTypes.some((compatible) => compatible.includes(jobLabelType) && compatible.includes(modelLabelType)); } diff --git a/cvat/apps/lambda_manager/views.py b/cvat/apps/lambda_manager/views.py index 6ea48a6ff564..9edb5889ae75 100644 --- a/cvat/apps/lambda_manager/views.py +++ b/cvat/apps/lambda_manager/views.py @@ -202,7 +202,7 @@ def parse_attributes(attrs_spec): for label in spec: parsed_label = { "name": label["name"], - "type": label.get("type", "unknown"), + "type": label.get("type", "any"), "attributes": parse_attributes(label.get("attributes", [])), } if parsed_label["type"] == "skeleton": @@ -312,7 +312,7 @@ def labels_compatible(model_label: dict, task_label: Label) -> bool: return ( model_type == db_type or (db_type == "any" and model_type != "skeleton") - or (model_type == "unknown" and db_type != "skeleton") + or (model_type == "any" and db_type != "skeleton") or any( [ model_type in compatible and db_type in compatible