Skip to content

Commit 8afb5dd

Browse files
authored
Az/fix annotation dump upload (#1229)
* fixed upload annotation in case of frame step != 1 * fixed upload annotation in case of attribute value is empty
1 parent ad000a2 commit 8afb5dd

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

cvat/apps/annotation/annotation.py

+14-5
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def __init__(self, annotation_ir, db_task, scheme='', host='', create_callback=N
120120
self._MAX_ANNO_SIZE=30000
121121
self._frame_info = {}
122122
self._frame_mapping = {}
123+
self._frame_step = db_task.get_frame_step()
123124

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

@@ -270,7 +271,7 @@ def _export_attributes(self, attributes):
270271
def _export_tracked_shape(self, shape):
271272
return Annotation.TrackedShape(
272273
type=shape["type"],
273-
frame=self._db_task.start_frame + shape["frame"] * self._db_task.get_frame_step(),
274+
frame=self._db_task.start_frame + shape["frame"] * self._frame_step,
274275
points=shape["points"],
275276
occluded=shape["occluded"],
276277
outside=shape.get("outside", False),
@@ -283,7 +284,7 @@ def _export_labeled_shape(self, shape):
283284
return Annotation.LabeledShape(
284285
type=shape["type"],
285286
label=self._get_label_name(shape["label_id"]),
286-
frame=self._db_task.start_frame + shape["frame"] * self._db_task.get_frame_step(),
287+
frame=self._db_task.start_frame + shape["frame"] * self._frame_step,
287288
points=shape["points"],
288289
occluded=shape["occluded"],
289290
z_order=shape.get("z_order", 0),
@@ -293,7 +294,7 @@ def _export_labeled_shape(self, shape):
293294

294295
def _export_tag(self, tag):
295296
return Annotation.Tag(
296-
frame=self._db_task.start_frame + tag["frame"] * self._db_task.get_frame_step(),
297+
frame=self._db_task.start_frame + tag["frame"] * self._frame_step,
297298
label=self._get_label_name(tag["label_id"]),
298299
group=tag.get("group", 0),
299300
attributes=self._export_attributes(tag["attributes"]),
@@ -302,7 +303,7 @@ def _export_tag(self, tag):
302303
def group_by_frame(self):
303304
def _get_frame(annotations, shape):
304305
db_image = self._frame_info[shape["frame"]]
305-
frame = self._db_task.start_frame + shape["frame"] * self._db_task.get_frame_step()
306+
frame = self._db_task.start_frame + shape["frame"] * self._frame_step
306307
rpath = db_image['path'].split(os.path.sep)
307308
if len(rpath) != 1:
308309
rpath = os.path.sep.join(rpath[rpath.index(".upload")+1:])
@@ -359,6 +360,7 @@ def meta(self):
359360
def _import_tag(self, tag):
360361
_tag = tag._asdict()
361362
label_id = self._get_label_id(_tag.pop('label'))
363+
_tag['frame'] = (int(_tag['frame']) - self._db_task.start_frame) // self._frame_step
362364
_tag['label_id'] = label_id
363365
_tag['attributes'] = [self._import_attribute(label_id, attrib) for attrib in _tag['attributes']
364366
if self._get_attribute_id(label_id, attrib.name)]
@@ -373,6 +375,7 @@ def _import_attribute(self, label_id, attribute):
373375
def _import_shape(self, shape):
374376
_shape = shape._asdict()
375377
label_id = self._get_label_id(_shape.pop('label'))
378+
_shape['frame'] = (int(_shape['frame']) - self._db_task.start_frame) // self._frame_step
376379
_shape['label_id'] = label_id
377380
_shape['attributes'] = [self._import_attribute(label_id, attrib) for attrib in _shape['attributes']
378381
if self._get_attribute_id(label_id, attrib.name)]
@@ -381,11 +384,13 @@ def _import_shape(self, shape):
381384
def _import_track(self, track):
382385
_track = track._asdict()
383386
label_id = self._get_label_id(_track.pop('label'))
384-
_track['frame'] = min(shape.frame for shape in _track['shapes'])
387+
_track['frame'] = (min(int(shape.frame) for shape in _track['shapes']) - \
388+
self._db_task.start_frame) // self._frame_step
385389
_track['label_id'] = label_id
386390
_track['attributes'] = []
387391
_track['shapes'] = [shape._asdict() for shape in _track['shapes']]
388392
for shape in _track['shapes']:
393+
shape['frame'] = (int(shape['frame']) - self._db_task.start_frame) // self._frame_step
389394
_track['attributes'] = [self._import_attribute(label_id, attrib) for attrib in shape['attributes']
390395
if self._get_immutable_attribute_id(label_id, attrib.name)]
391396
shape['attributes'] = [self._import_attribute(label_id, attrib) for attrib in shape['attributes']
@@ -431,6 +436,10 @@ def _len(self):
431436
def frame_info(self):
432437
return self._frame_info
433438

439+
@property
440+
def frame_step(self):
441+
return self._frame_step
442+
434443
@staticmethod
435444
def _get_filename(path):
436445
return os.path.splitext(os.path.basename(path))[0]

cvat/apps/annotation/cvat.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ def dump_track(idx, track):
415415
outside=True,
416416
keyframe=True,
417417
z_order=shape.z_order,
418-
frame=shape.frame + 1,
418+
frame=shape.frame + annotations.frame_step,
419419
attributes=shape.attributes,
420420
),
421421
],
@@ -466,7 +466,7 @@ def load(file_object, annotations):
466466
if el.tag == 'attribute' and attributes is not None:
467467
attributes.append(annotations.Attribute(
468468
name=el.attrib['name'],
469-
value=el.text,
469+
value=el.text or "",
470470
))
471471
if el.tag in supported_shapes:
472472
if track is not None:

0 commit comments

Comments
 (0)