Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for WiderFace dataset format #2864

Merged
merged 16 commits into from
Mar 10, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ For more information about supported formats look at the
| [LabelMe 3.0](http://labelme.csail.mit.edu/Release3.0) | X | X |
| [ImageNet](http://www.image-net.org) | X | X |
| [CamVid](http://mi.eng.cam.ac.uk/research/projects/VideoRec/CamVid/) | X | X |
| [WIDER Face](http://shuoyang1213.me/WIDERFACE/) | X | X |

## Deep learning serverless functions for automatic labeling

Expand Down
30 changes: 30 additions & 0 deletions cvat/apps/dataset_manager/formats/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- [TF detection API](#tfrecord)
- [ImageNet](#imagenet)
- [CamVid](#camvid)
- [WIDER Face](#widerface)

## How to add a new annotation format support<a id="how-to-add"></a>

Expand Down Expand Up @@ -874,3 +875,32 @@ has own color which corresponds to a label.
Uploaded file: a zip archive of the structure above

- supported annotations: Polygons

### [WIDER Face](http://shuoyang1213.me/WIDERFACE/)<a id="widerface" />

#### WIDER Face Dumper

Downloaded file: a zip archive of the following structure:

```bash
taskname.zip/
zhiltsov-max marked this conversation as resolved.
Show resolved Hide resolved
├── labels.txt # optional
└── WIDER_<any_subset_name>/
└── images
├── 0--label0/
└── 0_label0_image1.jpg
└── 1--label1/
└── 1_label1_image2.jpg
└── wider_face_split/
└── wider_face_<any_subset_name>_bbx_gt.txt
```

- supported annotations: Rectangles (with attributes), Labels
- supported attributes: `blur`, `expression`, `illumination`, `occlused`, `pose`, `invalid`

#### WIDER Face Loader

Uploaded file: a zip archive of the structure above

- supported annotations: Rectangles (with attributes), Labels
- supported attributes: `blur`, `expression`, `illumination`, `occlused`, `pose`, `invalid`
1 change: 1 addition & 0 deletions cvat/apps/dataset_manager/formats/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,4 @@ def make_exporter(name):
import cvat.apps.dataset_manager.formats.yolo
import cvat.apps.dataset_manager.formats.imagenet
import cvat.apps.dataset_manager.formats.camvid
import cvat.apps.dataset_manager.formats.widerface
32 changes: 32 additions & 0 deletions cvat/apps/dataset_manager/formats/widerface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (C) 2021 Intel Corporation
#
# SPDX-License-Identifier: MIT

import zipfile
from tempfile import TemporaryDirectory

from datumaro.components.dataset import Dataset

from cvat.apps.dataset_manager.bindings import CvatTaskDataExtractor, \
import_dm_annotations
from cvat.apps.dataset_manager.util import make_zip_archive

from .registry import dm_env, exporter, importer


@exporter(name='WiderFace', ext='ZIP', version='1.0')
def _export(dst_file, task_data, save_images=False):
dataset = Dataset.from_extractors(CvatTaskDataExtractor(
task_data, include_images=save_images), env=dm_env)
with TemporaryDirectory() as temp_dir:
dataset.export(temp_dir, 'wider_face', save_images=save_images)

make_zip_archive(temp_dir, dst_file)

@importer(name='WiderFace', ext='ZIP', version='1.0')
def _import(src_file, task_data):
with TemporaryDirectory() as tmp_dir:
zipfile.ZipFile(src_file).extractall(tmp_dir)

dataset = Dataset.import_from(tmp_dir, 'wider_face', env=dm_env)
import_dm_annotations(dataset, task_data)
3 changes: 3 additions & 0 deletions cvat/apps/dataset_manager/tests/test_formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ def test_export_formats_query(self):
'YOLO 1.1',
'ImageNet 1.0',
'CamVid 1.0',
'WiderFace 1.0',
})

def test_import_formats_query(self):
Expand All @@ -289,6 +290,7 @@ def test_import_formats_query(self):
'YOLO 1.1',
'ImageNet 1.0',
'CamVid 1.0',
'WiderFace 1.0',
})

def test_exports(self):
Expand Down Expand Up @@ -326,6 +328,7 @@ def test_empty_images_are_exported(self):
('YOLO 1.1', 'yolo'),
('ImageNet 1.0', 'imagenet_txt'),
('CamVid 1.0', 'camvid'),
('WiderFace 1.0', 'wider_face'),
]:
with self.subTest(format=format_name):
if not dm.formats.registry.EXPORT_FORMATS[format_name].ENABLED:
Expand Down
54 changes: 54 additions & 0 deletions cvat/apps/engine/tests/test_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2597,6 +2597,32 @@ def _create_task(self, owner, assignee):
]
},
{"name": "person"},
{
"name": "widerface",
"attributes": [
{
"name": "blur",
"mutable": False,
"input_type": "select",
"default_value": "0",
"values": ["0", "1", "2"]
},
{
"name": "expression",
"mutable": False,
"input_type": "select",
"default_value": "0",
"values": ["0", "1"]
},
{
"name": "illumination",
"mutable": False,
"input_type": "select",
"default_value": "0",
"values": ["0", "1"]
},
]
},
]
}

Expand Down Expand Up @@ -3718,6 +3744,30 @@ def _get_initial_annotation(annotation_format):
"occluded": False,
}]

rectangle_shapes_with_wider_attrs = [{
"frame": 0,
"label_id": task["labels"][2]["id"],
"group": 0,
"source": "manual",
"attributes": [
{
"spec_id": task["labels"][2]["attributes"][0]["id"],
"value": task["labels"][2]["attributes"][0]["default_value"]
},
{
"spec_id": task["labels"][2]["attributes"][1]["id"],
"value": task["labels"][2]["attributes"][1]["values"][1]
},
{
"spec_id": task["labels"][2]["attributes"][2]["id"],
"value": task["labels"][2]["attributes"][2]["default_value"]
}
],
"points": [1.0, 2.1, 10.6, 53.22],
"type": "rectangle",
"occluded": False,
}]

rectangle_shapes_wo_attrs = [{
"frame": 1,
"label_id": task["labels"][1]["id"],
Expand Down Expand Up @@ -3855,6 +3905,10 @@ def _get_initial_annotation(annotation_format):
annotations["shapes"] = rectangle_shapes_wo_attrs \
+ polygon_shapes_wo_attrs

elif annotation_format == "WiderFace 1.0":
annotations["tags"] = tags_wo_attrs
annotations["shapes"] = rectangle_shapes_with_wider_attrs

else:
raise Exception("Unknown format {}".format(annotation_format))

Expand Down