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 all 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Pre-built [cvat_server](https://hub.docker.com/r/openvino/cvat_server) and
[cvat_ui](https://hub.docker.com/r/openvino/cvat_ui) images were published on DockerHub (<https://github.com/openvinotoolkit/cvat/pull/2766>)
- Project task subsets (<https://github.com/openvinotoolkit/cvat/pull/2774>)
- [WiderFace](http://shuoyang1213.me/WIDERFACE/) format support (<https://github.com/openvinotoolkit/cvat/pull/2864>)
- [VGGFace2](https://github.com/ox-vgg/vgg_face2) format support (<https://github.com/openvinotoolkit/cvat/pull/2865>)

### Changed

Expand Down
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 |
| [VGGFace2](https://github.com/ox-vgg/vgg_face2) | X | X |

## Deep learning serverless functions for automatic labeling
Expand Down
31 changes: 31 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)
- [VGGFace2](#vggface2)

## How to add a new annotation format support<a id="how-to-add"></a>
Expand Down Expand Up @@ -876,6 +877,36 @@ 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_face_split/
│ └── wider_face_<any_subset_name>_bbx_gt.txt
└── WIDER_<any_subset_name>/
└── images/
├── 0--label0/
│ └── 0_label0_image1.jpg
└── 1--label1/
└── 1_label1_image2.jpg
```

- supported annotations: Rectangles (with attributes), Labels
- supported attributes: `blur`, `expression`, `illumination`,
`occluded` (both the annotation property & an attribute), `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`, `occluded`, `pose`, `invalid`

### [VGGFace2](https://github.com/ox-vgg/vgg_face2)<a id="vggface2" />

#### VGGFace2 Dumper
Expand Down
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,4 +95,5 @@ 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
import cvat.apps.dataset_manager.formats.vggface2
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 @@ -282,6 +282,7 @@ def test_export_formats_query(self):
'YOLO 1.1',
'ImageNet 1.0',
'CamVid 1.0',
'WiderFace 1.0',
'VGGFace2 1.0',
})

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

Expand Down Expand Up @@ -342,6 +344,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'),
('VGGFace2 1.0', 'vgg_face2'),
]:
with self.subTest(format=format_name):
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 @@ -2595,6 +2595,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 @@ -3716,6 +3742,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 @@ -3864,6 +3914,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

elif annotation_format == "VGGFace2 1.0":
annotations["tags"] = tags_wo_attrs
annotations["shapes"] = points_wo_attrs \
Expand Down