Skip to content

Commit

Permalink
Use any as the default function label type (#9050)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
SpecLad authored Feb 6, 2025
1 parent 1872b51 commit fec040d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions changelog.d/20250204_183545_roman_unknown_any.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Changed

- When invoking Nuclio functions, labels of type `any` can now be mapped to
labels of all types except `skeleton`
(<https://github.com/cvat-ai/cvat/pull/9050>)
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand Down
4 changes: 2 additions & 2 deletions cvat/apps/lambda_manager/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit fec040d

Please sign in to comment.