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

Add LFW format #3770

Merged
merged 9 commits into from
Nov 9, 2021
Merged
Changes from 7 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 CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add a tutorial on attaching cloud storage AWS-S3 (<https://github.com/openvinotoolkit/cvat/pull/3745>)
and Azure Blob Container (<https://github.com/openvinotoolkit/cvat/pull/3778>)
- The feature to remove annotations in a specified range of frames (<https://github.com/openvinotoolkit/cvat/pull/3617>)
- Add LFW format (<https://github.com/openvinotoolkit/cvat/pull/3770>)

### Changed

32 changes: 32 additions & 0 deletions cvat/apps/dataset_manager/formats/lfw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (C) 2021 Intel Corporation
#
# SPDX-License-Identifier: MIT
from tempfile import TemporaryDirectory

from datumaro.components.dataset import Dataset
from pyunpack import Archive

from cvat.apps.dataset_manager.bindings import (GetCVATDataExtractor,
import_dm_annotations)
from cvat.apps.dataset_manager.util import make_zip_archive

from .registry import dm_env, exporter, importer


@importer(name='LFW', ext='ZIP', version='1.0')
def _import(src_file, instance_data):
with TemporaryDirectory() as tmp_dir:
Archive(src_file.name).extractall(tmp_dir)

dataset = Dataset.import_from(tmp_dir, 'lfw')

import_dm_annotations(dataset, instance_data)

@exporter(name='LFW', ext='ZIP', version='1.0')
def _exporter(dst_file, instance_data, save_images=False):
dataset = Dataset.from_extractors(GetCVATDataExtractor(instance_data,
include_images=save_images), env=dm_env)
with TemporaryDirectory() as tmp_dir:
dataset.export(tmp_dir, format='lfw', save_images=save_images)

make_zip_archive(tmp_dir, dst_file)
2 changes: 1 addition & 1 deletion cvat/apps/dataset_manager/formats/registry.py
Original file line number Diff line number Diff line change
@@ -121,4 +121,4 @@ def make_exporter(name):
import cvat.apps.dataset_manager.formats.icdar
import cvat.apps.dataset_manager.formats.velodynepoint
import cvat.apps.dataset_manager.formats.pointcloud

import cvat.apps.dataset_manager.formats.lfw
26 changes: 26 additions & 0 deletions cvat/apps/dataset_manager/tests/assets/annotations.json
Original file line number Diff line number Diff line change
@@ -1168,5 +1168,31 @@
}
],
"tracks": []
},
"LFW 1.0": {
"version": 0,
"tags": [
{
"frame": 0,
"label_id": null,
"group": 0,
"source": "manual",
"attributes": []
}
],
"shapes": [
{
"type": "points",
"occluded": false,
"z_order": 0,
"points": [18.0, 8.0, 26.5, 17.7, 26.5, 23.7, 16.9, 23.2, 30.3, 28.0],
"frame": 0,
"label_id": null,
"group": 0,
"source": "manual",
"attributes": []
}
],
"tracks": []
}
}
8 changes: 5 additions & 3 deletions cvat/apps/dataset_manager/tests/test_formats.py
Original file line number Diff line number Diff line change
@@ -295,8 +295,8 @@ def test_export_formats_query(self):
'ICDAR Localization 1.0',
'ICDAR Segmentation 1.0',
'Kitti Raw Format 1.0',
'Sly Point Cloud Format 1.0'

'Sly Point Cloud Format 1.0',
'LFW 1.0',
})

def test_import_formats_query(self):
@@ -323,8 +323,9 @@ def test_import_formats_query(self):
'ICDAR Segmentation 1.0',
'Kitti Raw Format 1.0',
'Sly Point Cloud Format 1.0',
'LFW 1.0',
'Datumaro 1.0',
'Datumaro 3D 1.0'
'Datumaro 3D 1.0',
})

def test_exports(self):
@@ -371,6 +372,7 @@ def test_empty_images_are_exported(self):
('ICDAR Recognition 1.0', 'icdar_word_recognition'),
('ICDAR Localization 1.0', 'icdar_text_localization'),
('ICDAR Segmentation 1.0', 'icdar_text_segmentation'),
('LFW 1.0', 'lfw')
]:
with self.subTest(format=format_name):
if not dm.formats.registry.EXPORT_FORMATS[format_name].ENABLED:
3 changes: 2 additions & 1 deletion cvat/apps/dataset_manager/tests/test_rest_api_formats.py
Original file line number Diff line number Diff line change
@@ -1028,7 +1028,8 @@ def test_api_v1_tasks_annotations_dump_and_upload_with_datumaro(self):
"MOT 1.1", "MOTS PNG 1.0", \
"PASCAL VOC 1.1", "Segmentation mask 1.1", \
"TFRecord 1.0", "YOLO 1.1", "ImageNet 1.0", \
"WiderFace 1.0", "VGGFace2 1.0", "Datumaro 1.0", \
"WiderFace 1.0", "VGGFace2 1.0", "LFW 1.0", \
"Datumaro 1.0", \
]:
self._create_annotations(task, dump_format_name, "default")
else:
4 changes: 4 additions & 0 deletions cvat/apps/engine/tests/test_rest_api.py
Original file line number Diff line number Diff line change
@@ -4811,6 +4811,10 @@ def _get_initial_annotation(annotation_format):
annotations["shapes"] = points_wo_attrs \
+ rectangle_shapes_wo_attrs

elif annotation_format == "LFW 1.0":
annotations["shapes"] = points_wo_attrs \
+ tags_wo_attrs

elif annotation_format == "Market-1501 1.0":
tags_with_attrs = [{
"frame": 1,
77 changes: 77 additions & 0 deletions site/content/en/docs/manual/advanced/formats/format-lfw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
linkTitle: 'LFW'
weight: 17
---

# [LFW](http://vis-www.cs.umass.edu/lfw/)

- Format specification available [here](http://vis-www.cs.umass.edu/lfw/README.txt)

- Supported annotations: tags, points.

- Supported attributes:

- `negative_pairs` (should be defined for labels as `text`):
list of image names with mismatched persons.
- `positive_pairs` (should be defined for labels as `text`):
list of image names with matched persons.

# Import LFW annotation

The uploaded annotations file should be a zip file with the following structure:

```bash
<archive_name>.zip/
└── annotations/
├── landmarks.txt # list with landmark points for each image
├── pairs.txt # list of matched and mismatched pairs of person
└── people.txt # list of persons name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't the file optional now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's. Added clarification about it.

```

Full information about the content of annotation files is available
[here](http://vis-www.cs.umass.edu/lfw/README.txt)

# Export LFW annotation

Downloaded file: a zip archive of the following structure:

```bash
<archive_name>.zip/
└── images/ # if the option save images was selected
│ ├── name1/
│ │ ├── name1_0001.jpg
│ │ ├── name1_0002.jpg
│ │ ├── ...
│ ├── name2/
│ │ ├── name2_0001.jpg
│ │ ├── name2_0002.jpg
│ │ ├── ...
│ ├── ...
├── landmarks.txt
├── pairs.txt
└── people.txt
```

# Example: create task with images and upload LFW annotations into it

This is one of the possible ways to create a task and add LFW annotations for it.

- On the task creation page:
- Add labels that correspond to the names of the persons.
- For each label define `text` attributes with names `positive_pairs` and
`negative_pairs`
- Add images using zip archive from local repository:

```bash
images.zip/
├── name1_0001.jpg
├── name1_0002.jpg
├── ...
├── name1_<N>.jpg
├── name2_0001.jpg
├── ...
```

- On the annotation page:
Upload annotation -> LFW 1.0 -> choose archive with structure
that described in the [import section](#import-lfw-annotation).
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ context('Import annotations for frames with dots in name.', { browser: '!firefox
const createRectangleShape2Points = {
points: 'By 2 Points',
type: 'Shape',
labelName: labelName,
labelName,
firstX: 250,
firstY: 350,
secondX: 350,
@@ -70,9 +70,14 @@ context('Import annotations for frames with dots in name.', { browser: '!firefox
cy.get('.cvat-modal-export-task').find('.cvat-modal-export-select').click();
cy.get('.ant-select-dropdown')
.not('.ant-select-dropdown-hidden')
.trigger('wheel', {deltaY: 700})
.contains('.cvat-modal-export-option-item', dumpType)
.click();
.within(() => {
cy.get('.rc-virtual-list-holder')
.trigger('wheel', { deltaY: 1000 })
.trigger('wheel', { deltaY: 1000 })
.contains('.cvat-modal-export-option-item', dumpType)
.should('be.visible')
.click();
});
cy.get('.cvat-modal-export-select').should('contain.text', dumpType);
cy.get('.cvat-modal-export-task').contains('button', 'OK').click();
cy.wait('@dumpAnnotations', { timeout: 5000 }).its('response.statusCode').should('equal', 202);
@@ -92,6 +97,7 @@ context('Import annotations for frames with dots in name.', { browser: '!firefox
it('Upload annotation with YOLO format to job.', () => {
cy.interactMenu('Upload annotations');
cy.contains('.cvat-menu-load-submenu-item', dumpType.split(' ')[0])
.scrollIntoView()
.should('be.visible')
.within(() => {
cy.get('.cvat-menu-load-submenu-item-button')