Skip to content

Commit

Permalink
Exclude outside shapes from per frame export
Browse files Browse the repository at this point in the history
  • Loading branch information
zhiltsov-max committed Oct 22, 2020
1 parent 2799f4b commit a29446d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
8 changes: 3 additions & 5 deletions cvat/apps/dataset_manager/bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ def get_frame(idx):
for shape in sorted(anno_manager.to_shapes(self._db_task.data.size),
key=lambda shape: shape.get("z_order", 0)):
if 'track_id' in shape:
if shape['outside']:
continue
exported_shape = self._export_tracked_shape(shape)
else:
exported_shape = self._export_labeled_shape(shape)
Expand Down Expand Up @@ -450,10 +452,9 @@ def match_frame_fuzzy(self, path):
return None

class CvatTaskDataExtractor(datumaro.SourceExtractor):
def __init__(self, task_data, include_images=False, include_outside=False):
def __init__(self, task_data, include_images=False):
super().__init__()
self._categories = self._load_categories(task_data)
self._include_outside = include_outside

dm_items = []

Expand Down Expand Up @@ -550,9 +551,6 @@ def convert_attrs(label, cvat_attrs):
anno_attr['track_id'] = shape_obj.track_id
anno_attr['keyframe'] = shape_obj.keyframe

if not self._include_outside and shape_obj.outside:
continue

anno_points = shape_obj.points
if shape_obj.type == ShapeType.POINTS:
anno = datumaro.Points(anno_points,
Expand Down
19 changes: 15 additions & 4 deletions cvat/apps/dataset_manager/tests/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,13 +364,24 @@ def test_can_skip_outside(self):
task_ann.init_from_db()
task_data = TaskData(task_ann.ir_data, Task.objects.get(pk=task["id"]))

extractor = CvatTaskDataExtractor(task_data, include_outside=False)
extractor = CvatTaskDataExtractor(task_data)
dm_dataset = datumaro.components.project.Dataset.from_extractors(extractor)
self.assertEqual(4, len(dm_dataset.get("image_1").annotations))

extractor = CvatTaskDataExtractor(task_data, include_outside=True)
dm_dataset = datumaro.components.project.Dataset.from_extractors(extractor)
self.assertEqual(5, len(dm_dataset.get("image_1").annotations))
def test_no_outside_shapes_in_per_frame_export(self):
images = self._generate_task_images(3)
task = self._generate_task(images)
self._generate_annotations(task)
task_ann = TaskAnnotation(task["id"])
task_ann.init_from_db()
task_data = TaskData(task_ann.ir_data, Task.objects.get(pk=task["id"]))

outside_count = 0
for f in task_data.group_by_frame(include_empty=True):
for ann in f.labeled_shapes:
if getattr(ann, 'outside', None):
outside_count += 1
self.assertEqual(0, outside_count)

def test_cant_make_rel_frame_id_from_unknown(self):
images = self._generate_task_images(3)
Expand Down

0 comments on commit a29446d

Please sign in to comment.