-
Notifications
You must be signed in to change notification settings - Fork 3k
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 Open Images format #3679
Merged
Merged
Add Open Images format #3679
Changes from 8 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
96fcd2c
Update Datumaro dependency to 0.1.11
f65ca1a
Add Open Images format
c8a39a6
Add tests
5ba4b9e
Add documentation file
4270e12
Merge branch develop into sk/add-open-images-format
3a0f721
Fix incorrect format version
b64737f
Update tests
027bbbd
Ignore bandit warning
bdb366a
Fix UI test
57dc2db
Update CHANGELOG
2edd233
Fix linter issues
7b39e1a
Fix typo
a18af8e
Merge branch 'develop' into sk/add-open-images-format
1668396
Merge branch 'sk/add-open-images-format' of https://github.com/openvi…
8cdfbe5
Update format name
6b95a79
Update format name in tests
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Copyright (C) 2021 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
import glob | ||
import os.path as osp | ||
from tempfile import TemporaryDirectory | ||
|
||
from datumaro.components.dataset import Dataset, DatasetItem | ||
from datumaro.plugins.open_images_format import OpenImagesPath | ||
from datumaro.util.image import DEFAULT_IMAGE_META_FILE_NAME | ||
from pyunpack import Archive | ||
|
||
from cvat.apps.dataset_manager.bindings import (GetCVATDataExtractor, | ||
find_dataset_root, import_dm_annotations, match_dm_item) | ||
from cvat.apps.dataset_manager.util import make_zip_archive | ||
|
||
from .registry import dm_env, exporter, importer | ||
|
||
|
||
def find_item_ids(path): | ||
image_desc_patterns = ( | ||
OpenImagesPath.FULL_IMAGE_DESCRIPTION_FILE_NAME, | ||
*OpenImagesPath.SUBSET_IMAGE_DESCRIPTION_FILE_PATTERNS | ||
) | ||
|
||
image_desc_patterns = ( | ||
osp.join(path, OpenImagesPath.ANNOTATIONS_DIR, pattern) | ||
for pattern in image_desc_patterns | ||
) | ||
|
||
for pattern in image_desc_patterns: | ||
for path in glob.glob(pattern): | ||
with open(path, 'r') as desc: | ||
next(desc) | ||
for row in desc: | ||
yield row.split(',')[0] | ||
|
||
@exporter(name='Open Images', ext='ZIP', version='1.0') | ||
def _export(dst_file, task_data, save_images=False): | ||
dataset = Dataset.from_extractors(GetCVATDataExtractor( | ||
task_data, include_images=save_images), env=dm_env) | ||
dataset.transform('polygons_to_masks') | ||
dataset.transform('merge_instance_segments') | ||
|
||
with TemporaryDirectory() as temp_dir: | ||
dataset.export(temp_dir, 'open_images', save_images=save_images) | ||
|
||
make_zip_archive(temp_dir, dst_file) | ||
|
||
@importer(name='Open Images', ext='ZIP', version='1.0') | ||
def _import(src_file, task_data): | ||
with TemporaryDirectory() as tmp_dir: | ||
Archive(src_file.name).extractall(tmp_dir) | ||
|
||
image_meta_path = osp.join(tmp_dir, OpenImagesPath.ANNOTATIONS_DIR, | ||
DEFAULT_IMAGE_META_FILE_NAME) | ||
image_meta = None | ||
|
||
if not osp.isfile(image_meta_path): | ||
image_meta = {} | ||
item_ids = list(find_item_ids(tmp_dir)) | ||
|
||
root_hint = find_dataset_root( | ||
[DatasetItem(id=item_id) for item_id in item_ids], task_data) | ||
|
||
for item_id in item_ids: | ||
frame_info = None | ||
try: | ||
frame_id = match_dm_item(DatasetItem(id=item_id), | ||
task_data, root_hint) | ||
frame_info = task_data.frame_info[frame_id] | ||
except Exception: # nosec | ||
pass | ||
if frame_info is not None: | ||
image_meta[item_id] = (frame_info['height'], frame_info['width']) | ||
|
||
dataset = Dataset.import_from(tmp_dir, 'open_images', | ||
image_meta=image_meta, env=dm_env) | ||
dataset.transform('masks_to_polygons') | ||
import_dm_annotations(dataset, task_data) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
site/content/en/docs/manual/advanced/formats/format-openimages.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
--- | ||
linkTitle: 'Open Images' | ||
weight: 15 | ||
--- | ||
|
||
# [Open Images](https://storage.googleapis.com/openimages/web/index.html) | ||
|
||
- [Format specification](https://storage.googleapis.com/openimages/web/download.html) | ||
|
||
- Supported annotations: | ||
|
||
- Rectangles (detection task) | ||
- Tags (classification task) | ||
- Polygons (segmentation task) | ||
|
||
- Supported attributes: | ||
|
||
- Labels | ||
|
||
- `score` (should be defined for labels as `text` or `number`). | ||
The confidence level from 0 to 1. | ||
|
||
- Bounding boxes | ||
|
||
- `score` (should be defined for labels as `text` or `number`). | ||
The confidence level from 0 to 1. | ||
- `occluded` (both UI option and a separate attribute). | ||
Whether the object is occluded by another object. | ||
- `truncated` (should be defined for labels as `checkbox` -es). | ||
Whether the object extends beyond the boundary of the image. | ||
- `is_group_of` (should be defined for labels as `checkbox` -es). | ||
Whether the object represents a group of objects of the same class. | ||
- `is_depiction` (should be defined for labels as `checkbox` -es). | ||
Whether the object is a depiction (such as a drawing) | ||
rather than a real object. | ||
- `is_inside` (should be defined for labels as `checkbox` -es). | ||
Whether the object is seen from the inside. | ||
|
||
- Masks | ||
- `box_id` (should be defined for labels as `text`). | ||
An identifier for the bounding box associated with the mask. | ||
- `predicted_iou` (should be defined for labels as `text` or `number`). | ||
Predicted IoU value with respect to the ground truth. | ||
|
||
## Open Images export | ||
|
||
Downloaded file: a zip archive of the following structure: | ||
|
||
``` | ||
└─ taskname.zip/ | ||
├── annotations/ | ||
│ ├── bbox_labels_600_hierarchy.json | ||
│ ├── class-descriptions.csv | ||
| ├── images.meta # additional file with information about image sizes | ||
│ ├── <subset_name>-image_ids_and_rotation.csv | ||
│ ├── <subset_name>-annotations-bbox.csv | ||
│ ├── <subset_name>-annotations-human-imagelabels.csv | ||
│ └── <subset_name>-annotations-object-segmentation.csv | ||
├── images/ | ||
│ ├── subset1/ | ||
│ │ ├── <image_name101.jpg> | ||
│ │ ├── <image_name102.jpg> | ||
│ │ └── ... | ||
│ ├── subset2/ | ||
│ │ ├── <image_name201.jpg> | ||
│ │ ├── <image_name202.jpg> | ||
│ │ └── ... | ||
| ├── ... | ||
└── masks/ | ||
├── subset1/ | ||
│ ├── <mask_name101.png> | ||
│ ├── <mask_name102.png> | ||
│ └── ... | ||
├── subset2/ | ||
│ ├── <mask_name201.png> | ||
│ ├── <mask_name202.png> | ||
│ └── ... | ||
├── ... | ||
``` | ||
|
||
## Open Images import | ||
|
||
Uploaded file: a zip archive of the following structure: | ||
|
||
``` | ||
└─ upload.zip/ | ||
├── annotations/ | ||
│ ├── bbox_labels_600_hierarchy.json | ||
│ ├── class-descriptions.csv | ||
| ├── images.meta # optional, file with information about image sizes | ||
│ ├── <subset_name>-image_ids_and_rotation.csv | ||
│ ├── <subset_name>-annotations-bbox.csv | ||
│ ├── <subset_name>-annotations-human-imagelabels.csv | ||
│ └── <subset_name>-annotations-object-segmentation.csv | ||
└── masks/ | ||
├── subset1/ | ||
│ ├── <mask_name101.png> | ||
│ ├── <mask_name102.png> | ||
│ └── ... | ||
├── subset2/ | ||
│ ├── <mask_name201.png> | ||
│ ├── <mask_name202.png> | ||
│ └── ... | ||
├── ... | ||
``` | ||
|
||
Image ids in the `<subset_name>-image_ids_and_rotation.csv` should match with | ||
image names in the task. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe, we should be more specific about the version and add
v6
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.