Skip to content

Commit

Permalink
annotation_type field support for tags, tf_annotation api, cvat-dumpe…
Browse files Browse the repository at this point in the history
…r/loader
  • Loading branch information
Priya4607 committed Mar 23, 2020
1 parent fd3e896 commit 1ec2869
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 3 deletions.
9 changes: 6 additions & 3 deletions cvat/apps/annotation/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,12 @@ def reset(self):

class Annotation:
Attribute = namedtuple('Attribute', 'name, value')
LabeledShape = namedtuple('LabeledShape', 'type, frame, label, points, occluded, attributes, group, z_order')
LabeledShape = namedtuple('LabeledShape', 'type, frame, label, points, occluded, attributes, group, z_order, annotation_type')
LabeledShape.__new__.__defaults__ = (0, 0)
TrackedShape = namedtuple('TrackedShape', 'type, points, occluded, frame, attributes, outside, keyframe, z_order')
TrackedShape = namedtuple('TrackedShape', 'type, points, occluded, frame, attributes, outside, keyframe, z_order, annotation_type')
TrackedShape.__new__.__defaults__ = (0, )
Track = namedtuple('Track', 'label, group, shapes')
Tag = namedtuple('Tag', 'frame, label, attributes, group')
Tag = namedtuple('Tag', 'frame, label, attributes, group, annotation_type')
Tag.__new__.__defaults__ = (0, )
Frame = namedtuple('Frame', 'frame, name, width, height, labeled_shapes, tags')

Expand Down Expand Up @@ -278,6 +278,7 @@ def _export_tracked_shape(self, shape):
keyframe=shape.get("keyframe", True),
z_order=shape["z_order"],
attributes=self._export_attributes(shape["attributes"]),
annotation_type=shape.get("annotation_type", "Manual"),
)

def _export_labeled_shape(self, shape):
Expand All @@ -290,6 +291,7 @@ def _export_labeled_shape(self, shape):
z_order=shape.get("z_order", 0),
group=shape.get("group", 0),
attributes=self._export_attributes(shape["attributes"]),
annotation_type=shape.get("annotation_type", "Manual"),
)

def _export_tag(self, tag):
Expand All @@ -298,6 +300,7 @@ def _export_tag(self, tag):
label=self._get_label_name(tag["label_id"]),
group=tag.get("group", 0),
attributes=self._export_attributes(tag["attributes"]),
annotation_type=tag.get("annotation_type", "Manual"),
)

def group_by_frame(self):
Expand Down
6 changes: 6 additions & 0 deletions cvat/apps/annotation/cvat.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ def dump_as_cvat_annotation(file_object, annotations):
dump_data = OrderedDict([
("label", shape.label),
("occluded", str(int(shape.occluded))),
("annotation_type", shape.annotation_type),
])

if shape.type == "rectangle":
Expand Down Expand Up @@ -281,6 +282,7 @@ def dump_as_cvat_annotation(file_object, annotations):
for tag in frame_annotation.tags:
tag_data = OrderedDict([
("label", tag.label),
("annotation_type", tag.annotation_type),
])
if tag.group:
tag_data["group_id"] = str(tag.group)
Expand Down Expand Up @@ -407,6 +409,7 @@ def dump_track(idx, track):
z_order=shape.z_order,
frame=shape.frame,
attributes=shape.attributes,
annotation_type=shape.annotation_type,
),
annotations.TrackedShape(
type=shape.type,
Expand All @@ -417,6 +420,7 @@ def dump_track(idx, track):
z_order=shape.z_order,
frame=shape.frame + annotations.frame_step,
attributes=shape.attributes,
annotation_type=shape.annotation_type,
),
],
))
Expand Down Expand Up @@ -461,6 +465,7 @@ def load(file_object, annotations):
'label': el.attrib['label'],
'group': int(el.attrib.get('group_id', 0)),
'attributes': attributes,
'annotation_type': el.attrib["annotation_type"],
}
elif ev == 'end':
if el.tag == 'attribute' and attributes is not None:
Expand All @@ -481,6 +486,7 @@ def load(file_object, annotations):
shape['type'] = 'rectangle' if el.tag == 'box' else el.tag
shape['occluded'] = el.attrib['occluded'] == '1'
shape['z_order'] = int(el.attrib.get('z_order', 0))
shape['annotation_type'] = el.attrib.get('annotation_type', 'Manual')

if el.tag == 'box':
shape['points'].append(el.attrib['xtl'])
Expand Down
3 changes: 3 additions & 0 deletions cvat/apps/engine/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ def _init_tags_from_db(self):
'frame',
'label_id',
'group',
'annotation_type',
'labeledimageattributeval__spec_id',
'labeledimageattributeval__value',
'labeledimageattributeval__id',
Expand Down Expand Up @@ -516,6 +517,7 @@ def _init_shapes_from_db(self):
'occluded',
'z_order',
'points',
'annotation_type',
'labeledshapeattributeval__spec_id',
'labeledshapeattributeval__value',
'labeledshapeattributeval__id',
Expand Down Expand Up @@ -549,6 +551,7 @@ def _init_tracks_from_db(self):
"frame",
"label_id",
"group",
"annotation_type",
"labeledtrackattributeval__spec_id",
"labeledtrackattributeval__value",
"labeledtrackattributeval__id",
Expand Down
12 changes: 12 additions & 0 deletions cvat/apps/engine/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,24 @@ def choices(self):
def __str__(self):
return self.value

class AnnotationType(str, Enum):
AUTO = 'Auto'
MANUAL = 'Manual'

@classmethod
def choices(self):
return tuple((x.value, x.name) for x in self)

def __str__(self):
return self.value

class Annotation(models.Model):
id = models.BigAutoField(primary_key=True)
job = models.ForeignKey(Job, on_delete=models.CASCADE)
label = models.ForeignKey(Label, on_delete=models.CASCADE)
frame = models.PositiveIntegerField()
group = models.PositiveIntegerField(null=True)
annotation_type = models.CharField(max_length=16, choices=AnnotationType.choices(), default="Manual", null=True)

class Meta:
abstract = True
Expand Down
1 change: 1 addition & 0 deletions cvat/apps/engine/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ class AnnotationSerializer(serializers.Serializer):
frame = serializers.IntegerField(min_value=0)
label_id = serializers.IntegerField(min_value=0)
group = serializers.IntegerField(min_value=0, allow_null=True)
annotation_type = serializers.CharField(default = 'Manual')

class LabeledImageSerializer(AnnotationSerializer):
attributes = AttributeValSerializer(many=True,
Expand Down
1 change: 1 addition & 0 deletions cvat/apps/tf_annotation/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ def convert_to_cvat_format(data):
"group": None,
"occluded": False,
"attributes": [],
"annotation_type": "Auto",
})

return result
Expand Down

0 comments on commit 1ec2869

Please sign in to comment.