Skip to content

Commit

Permalink
Merge branch 'develop' into kl/copy-frame-name-button
Browse files Browse the repository at this point in the history
  • Loading branch information
klakhov authored Jan 29, 2025
2 parents 482cd7a + fa0e3f1 commit 0aa1710
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 39 deletions.
4 changes: 4 additions & 0 deletions changelog.d/20250122_142453_roman_labeltype_choicefield.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Fixed

- The backend now rejects invalid label types
(<https://github.com/cvat-ai/cvat/pull/8980>)
35 changes: 35 additions & 0 deletions cvat/apps/engine/migrations/0087_alter_label_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Generated by Django 4.2.17 on 2025-01-22 13:48

from django.db import migrations, models

import cvat.apps.engine.models


class Migration(migrations.Migration):

dependencies = [
("engine", "0086_profile_has_analytics_access"),
]

operations = [
migrations.AlterField(
model_name="label",
name="type",
field=models.CharField(
choices=[
("any", "ANY"),
("cuboid", "CUBOID"),
("ellipse", "ELLIPSE"),
("mask", "MASK"),
("points", "POINTS"),
("polygon", "POLYGON"),
("polyline", "POLYLINE"),
("rectangle", "RECTANGLE"),
("skeleton", "SKELETON"),
("tag", "TAG"),
],
default=cvat.apps.engine.models.LabelType["ANY"],
max_length=32,
),
),
]
12 changes: 6 additions & 6 deletions cvat/apps/engine/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ def __str__(self):
return self.value

class LabelType(str, Enum):
BBOX = 'bbox'
ANY = 'any'
CUBOID = 'cuboid'
ELLIPSE = 'ellipse'
MASK = 'mask'
POINTS = 'points'
POLYGON = 'polygon'
POLYLINE = 'polyline'
POINTS = 'points'
CUBOID = 'cuboid'
CUBOID_3D = 'cuboid_3d'
RECTANGLE = 'rectangle'
SKELETON = 'skeleton'
TAG = 'tag'
ANY = 'any'

@classmethod
def choices(cls):
Expand Down Expand Up @@ -946,7 +946,7 @@ class Label(models.Model):
project = models.ForeignKey(Project, null=True, blank=True, on_delete=models.CASCADE)
name = SafeCharField(max_length=64)
color = models.CharField(default='', max_length=8)
type = models.CharField(max_length=32, null=True, choices=LabelType.choices(), default=LabelType.ANY)
type = models.CharField(max_length=32, choices=LabelType.choices(), default=LabelType.ANY)
parent = models.ForeignKey('self', on_delete=models.CASCADE, null=True, blank=True, related_name='sublabels')

def __str__(self):
Expand Down
4 changes: 2 additions & 2 deletions cvat/apps/engine/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ class SublabelSerializer(serializers.ModelSerializer):
color = serializers.CharField(allow_blank=True, required=False,
help_text="The hex value for the RGB color. "
"Will be generated automatically, unless specified explicitly.")
type = serializers.CharField(allow_blank=True, required=False,
type = serializers.ChoiceField(choices=models.LabelType.choices(), required=False,
help_text="Associated annotation type for this label")
has_parent = serializers.BooleanField(source='has_parent_label', required=False)

Expand Down Expand Up @@ -418,7 +418,7 @@ def update_label(
try:
db_label = models.Label.create(
name=validated_data.get('name'),
type=validated_data.get('type'),
type=validated_data.get('type', models.LabelType.ANY),
parent=parent_label,
**parent_info
)
Expand Down
102 changes: 89 additions & 13 deletions cvat/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2809,16 +2809,16 @@ paths:
schema:
type: string
enum:
- bbox
- any
- cuboid
- ellipse
- mask
- points
- polygon
- polyline
- points
- cuboid
- cuboid_3d
- rectangle
- skeleton
- tag
- any
tags:
- labels
security:
Expand Down Expand Up @@ -8487,8 +8487,21 @@ components:
description: The list of attributes. If you want to remove an attribute,
you need to recreate the label and specify the remaining attributes.
type:
type: string
description: Associated annotation type for this label
allOf:
- $ref: '#/components/schemas/LabelType'
description: |-
Associated annotation type for this label
* `any` - ANY
* `cuboid` - CUBOID
* `ellipse` - ELLIPSE
* `mask` - MASK
* `points` - POINTS
* `polygon` - POLYGON
* `polyline` - POLYLINE
* `rectangle` - RECTANGLE
* `skeleton` - SKELETON
* `tag` - TAG
svg:
type: string
sublabels:
Expand Down Expand Up @@ -8531,6 +8544,30 @@ components:
a parent label
required:
- name
LabelType:
enum:
- any
- cuboid
- ellipse
- mask
- points
- polygon
- polyline
- rectangle
- skeleton
- tag
type: string
description: |-
* `any` - ANY
* `cuboid` - CUBOID
* `ellipse` - ELLIPSE
* `mask` - MASK
* `points` - POINTS
* `polygon` - POLYGON
* `polyline` - POLYLINE
* `rectangle` - RECTANGLE
* `skeleton` - SKELETON
* `tag` - TAG
LabeledData:
type: object
properties:
Expand Down Expand Up @@ -9589,8 +9626,21 @@ components:
description: Delete the label. Only applicable in the PATCH methods of a
project or a task.
type:
type: string
description: Associated annotation type for this label
allOf:
- $ref: '#/components/schemas/LabelType'
description: |-
Associated annotation type for this label
* `any` - ANY
* `cuboid` - CUBOID
* `ellipse` - ELLIPSE
* `mask` - MASK
* `points` - POINTS
* `polygon` - POLYGON
* `polyline` - POLYLINE
* `rectangle` - RECTANGLE
* `skeleton` - SKELETON
* `tag` - TAG
svg:
type: string
sublabels:
Expand Down Expand Up @@ -10764,8 +10814,21 @@ components:
description: The list of attributes. If you want to remove an attribute,
you need to recreate the label and specify the remaining attributes.
type:
type: string
description: Associated annotation type for this label
allOf:
- $ref: '#/components/schemas/LabelType'
description: |-
Associated annotation type for this label
* `any` - ANY
* `cuboid` - CUBOID
* `ellipse` - ELLIPSE
* `mask` - MASK
* `points` - POINTS
* `polygon` - POLYGON
* `polyline` - POLYLINE
* `rectangle` - RECTANGLE
* `skeleton` - SKELETON
* `tag` - TAG
has_parent:
type: boolean
required:
Expand Down Expand Up @@ -10804,8 +10867,21 @@ components:
description: The list of attributes. If you want to remove an attribute,
you need to recreate the label and specify the remaining attributes.
type:
type: string
description: Associated annotation type for this label
allOf:
- $ref: '#/components/schemas/LabelType'
description: |-
Associated annotation type for this label
* `any` - ANY
* `cuboid` - CUBOID
* `ellipse` - ELLIPSE
* `mask` - MASK
* `points` - POINTS
* `polygon` - POLYGON
* `polyline` - POLYLINE
* `rectangle` - RECTANGLE
* `skeleton` - SKELETON
* `tag` - TAG
has_parent:
type: boolean
required:
Expand Down
1 change: 1 addition & 0 deletions cvat/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,7 @@ class CVAT_QUEUES(Enum):
'COMPONENT_SPLIT_REQUEST': True,

'ENUM_NAME_OVERRIDES': {
'LabelType': 'cvat.apps.engine.models.LabelType',
'ShapeType': 'cvat.apps.engine.models.ShapeType',
'OperationStatus': 'cvat.apps.engine.models.StateChoice',
'ChunkType': 'cvat.apps.engine.models.DataChoice',
Expand Down
24 changes: 14 additions & 10 deletions serverless/pytorch/dschoerk/transt/nuclio/model_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,24 @@ def __init__(self):
self.tracker = Tracker(name='transt', net=net, window_penalty=0.49, exemplar_size=128, instance_size=256)

def decode_state(self, state):
self.tracker.net.net.zf = jsonpickle.decode(state['model.net.net.zf'])
self.tracker.net.net.pos_template = jsonpickle.decode(state['model.net.net.pos_template'])
# The server ensures that `state` is one of the values that the function itself
# has previously output. Therefore it should be safe to use jsonpickle.
decode = jsonpickle.decode # nosec: B301

self.tracker.window = jsonpickle.decode(state['model.window'])
self.tracker.center_pos = jsonpickle.decode(state['model.center_pos'])
self.tracker.size = jsonpickle.decode(state['model.size'])
self.tracker.channel_average = jsonpickle.decode(state['model.channel_average'])
self.tracker.mean = jsonpickle.decode(state['model.mean'])
self.tracker.std = jsonpickle.decode(state['model.std'])
self.tracker.inplace = jsonpickle.decode(state['model.inplace'])
self.tracker.net.net.zf = decode(state['model.net.net.zf'])
self.tracker.net.net.pos_template = decode(state['model.net.net.pos_template'])

self.tracker.window = decode(state['model.window'])
self.tracker.center_pos = decode(state['model.center_pos'])
self.tracker.size = decode(state['model.size'])
self.tracker.channel_average = decode(state['model.channel_average'])
self.tracker.mean = decode(state['model.mean'])
self.tracker.std = decode(state['model.std'])
self.tracker.inplace = decode(state['model.inplace'])

self.tracker.features_initialized = False
if 'model.features_initialized' in state:
self.tracker.features_initialized = jsonpickle.decode(state['model.features_initialized'])
self.tracker.features_initialized = decode(state['model.features_initialized'])

def encode_state(self):
state = {}
Expand Down
11 changes: 9 additions & 2 deletions serverless/pytorch/foolwood/siammask/nuclio/model_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
#
# SPDX-License-Identifier: MIT

from tools.test import *
import os
from copy import copy

import jsonpickle
import numpy as np
import torch

from tools.test import siamese_init, siamese_track
from utils.config_helper import load_config
from utils.load_helper import load_pretrain

class ModelHandler:
def __init__(self):
Expand Down Expand Up @@ -37,7 +42,9 @@ def encode_state(self, state):

def decode_state(self, state):
for k,v in state.items():
state[k] = jsonpickle.decode(v)
# The server ensures that `state` is one of the values that the function itself
# has previously output. Therefore it should be safe to use jsonpickle.
state[k] = jsonpickle.decode(v) # nosec: B301

state['net'] = copy(self.siammask)
state['net'].zf = state['net.zf']
Expand Down
2 changes: 1 addition & 1 deletion site/content/en/docs/manual/advanced/xml_format.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ For what is `rle`, see [Run-length encoding](https://en.wikipedia.org/wiki/Run-l
<labels>
<label>
<name>String: name of the label (e.g. car, person)</name>
<type>String: any, bbox, cuboid, cuboid_3d, ellipse, mask, polygon, polyline, points, skeleton, tag</type>
<type>String: any, bbox, cuboid, ellipse, mask, polygon, polyline, points, skeleton, tag</type>
<attributes>
<attribute>
<name>String: attribute name</name>
Expand Down
10 changes: 5 additions & 5 deletions tests/python/rest_api/test_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,16 +644,16 @@ def _get_patch_data(
"color": ["#2000c0"],
"name": ["modified"],
"type": [
"bbox",
"any",
"cuboid",
"ellipse",
"mask",
"points",
"polygon",
"polyline",
"points",
"cuboid",
"cuboid_3d",
"rectangle",
"skeleton",
"tag",
"any",
],
}.items()
)
Expand Down

0 comments on commit 0aa1710

Please sign in to comment.