Skip to content

Commit

Permalink
Az/fix annotation dump upload (#1229)
Browse files Browse the repository at this point in the history
* fixed upload annotation in case of frame step != 1

* fixed upload annotation in case of attribute value is empty
  • Loading branch information
azhavoro authored Mar 4, 2020
1 parent ad000a2 commit 8afb5dd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
19 changes: 14 additions & 5 deletions cvat/apps/annotation/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ def __init__(self, annotation_ir, db_task, scheme='', host='', create_callback=N
self._MAX_ANNO_SIZE=30000
self._frame_info = {}
self._frame_mapping = {}
self._frame_step = db_task.get_frame_step()

db_labels = self._db_task.label_set.all().prefetch_related('attributespec_set').order_by('pk')

Expand Down Expand Up @@ -270,7 +271,7 @@ def _export_attributes(self, attributes):
def _export_tracked_shape(self, shape):
return Annotation.TrackedShape(
type=shape["type"],
frame=self._db_task.start_frame + shape["frame"] * self._db_task.get_frame_step(),
frame=self._db_task.start_frame + shape["frame"] * self._frame_step,
points=shape["points"],
occluded=shape["occluded"],
outside=shape.get("outside", False),
Expand All @@ -283,7 +284,7 @@ def _export_labeled_shape(self, shape):
return Annotation.LabeledShape(
type=shape["type"],
label=self._get_label_name(shape["label_id"]),
frame=self._db_task.start_frame + shape["frame"] * self._db_task.get_frame_step(),
frame=self._db_task.start_frame + shape["frame"] * self._frame_step,
points=shape["points"],
occluded=shape["occluded"],
z_order=shape.get("z_order", 0),
Expand All @@ -293,7 +294,7 @@ def _export_labeled_shape(self, shape):

def _export_tag(self, tag):
return Annotation.Tag(
frame=self._db_task.start_frame + tag["frame"] * self._db_task.get_frame_step(),
frame=self._db_task.start_frame + tag["frame"] * self._frame_step,
label=self._get_label_name(tag["label_id"]),
group=tag.get("group", 0),
attributes=self._export_attributes(tag["attributes"]),
Expand All @@ -302,7 +303,7 @@ def _export_tag(self, tag):
def group_by_frame(self):
def _get_frame(annotations, shape):
db_image = self._frame_info[shape["frame"]]
frame = self._db_task.start_frame + shape["frame"] * self._db_task.get_frame_step()
frame = self._db_task.start_frame + shape["frame"] * self._frame_step
rpath = db_image['path'].split(os.path.sep)
if len(rpath) != 1:
rpath = os.path.sep.join(rpath[rpath.index(".upload")+1:])
Expand Down Expand Up @@ -359,6 +360,7 @@ def meta(self):
def _import_tag(self, tag):
_tag = tag._asdict()
label_id = self._get_label_id(_tag.pop('label'))
_tag['frame'] = (int(_tag['frame']) - self._db_task.start_frame) // self._frame_step
_tag['label_id'] = label_id
_tag['attributes'] = [self._import_attribute(label_id, attrib) for attrib in _tag['attributes']
if self._get_attribute_id(label_id, attrib.name)]
Expand All @@ -373,6 +375,7 @@ def _import_attribute(self, label_id, attribute):
def _import_shape(self, shape):
_shape = shape._asdict()
label_id = self._get_label_id(_shape.pop('label'))
_shape['frame'] = (int(_shape['frame']) - self._db_task.start_frame) // self._frame_step
_shape['label_id'] = label_id
_shape['attributes'] = [self._import_attribute(label_id, attrib) for attrib in _shape['attributes']
if self._get_attribute_id(label_id, attrib.name)]
Expand All @@ -381,11 +384,13 @@ def _import_shape(self, shape):
def _import_track(self, track):
_track = track._asdict()
label_id = self._get_label_id(_track.pop('label'))
_track['frame'] = min(shape.frame for shape in _track['shapes'])
_track['frame'] = (min(int(shape.frame) for shape in _track['shapes']) - \
self._db_task.start_frame) // self._frame_step
_track['label_id'] = label_id
_track['attributes'] = []
_track['shapes'] = [shape._asdict() for shape in _track['shapes']]
for shape in _track['shapes']:
shape['frame'] = (int(shape['frame']) - self._db_task.start_frame) // self._frame_step
_track['attributes'] = [self._import_attribute(label_id, attrib) for attrib in shape['attributes']
if self._get_immutable_attribute_id(label_id, attrib.name)]
shape['attributes'] = [self._import_attribute(label_id, attrib) for attrib in shape['attributes']
Expand Down Expand Up @@ -431,6 +436,10 @@ def _len(self):
def frame_info(self):
return self._frame_info

@property
def frame_step(self):
return self._frame_step

@staticmethod
def _get_filename(path):
return os.path.splitext(os.path.basename(path))[0]
Expand Down
4 changes: 2 additions & 2 deletions cvat/apps/annotation/cvat.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def dump_track(idx, track):
outside=True,
keyframe=True,
z_order=shape.z_order,
frame=shape.frame + 1,
frame=shape.frame + annotations.frame_step,
attributes=shape.attributes,
),
],
Expand Down Expand Up @@ -466,7 +466,7 @@ def load(file_object, annotations):
if el.tag == 'attribute' and attributes is not None:
attributes.append(annotations.Attribute(
name=el.attrib['name'],
value=el.text,
value=el.text or "",
))
if el.tag in supported_shapes:
if track is not None:
Expand Down

0 comments on commit 8afb5dd

Please sign in to comment.