-
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
Update Datumaro dependency to 0.2.0 #3813
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
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
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,67 @@ | ||
# Copyright (C) 2019 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: MIT | ||
|
||
from tempfile import TemporaryDirectory | ||
|
||
from datumaro.components.dataset import Dataset | ||
from datumaro.components.extractor import ItemTransform | ||
from datumaro.util.image import Image | ||
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 cvat.apps.engine.models import DimensionType | ||
|
||
from .registry import dm_env, exporter, importer | ||
|
||
class DeleteImagePath(ItemTransform): | ||
def transform_item(self, item): | ||
image = None | ||
if item.has_image and item.image.has_data: | ||
image = Image(data=item.image.data, size=item.image.size) | ||
return item.wrap(image=image, point_cloud='', related_images=[]) | ||
|
||
|
||
@exporter(name="Datumaro", ext="ZIP", version="1.0") | ||
def _export(dst_file, instance_data, save_images=False): | ||
dataset = Dataset.from_extractors(GetCVATDataExtractor( | ||
instance_data=instance_data, include_images=save_images), env=dm_env) | ||
if not save_images: | ||
dataset.transform(DeleteImagePath) | ||
with TemporaryDirectory() as tmp_dir: | ||
dataset.export(tmp_dir, 'datumaro', save_images=save_images) | ||
|
||
make_zip_archive(tmp_dir, dst_file) | ||
|
||
@importer(name="Datumaro", 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, 'datumaro', env=dm_env) | ||
|
||
import_dm_annotations(dataset, instance_data) | ||
|
||
@exporter(name="Datumaro 3D", ext="ZIP", version="1.0", dimension=DimensionType.DIM_3D) | ||
def _export(dst_file, instance_data, save_images=False): | ||
dataset = Dataset.from_extractors(GetCVATDataExtractor( | ||
instance_data=instance_data, include_images=save_images, | ||
dimension=DimensionType.DIM_3D), env=dm_env) | ||
|
||
if not save_images: | ||
dataset.transform(DeleteImagePath) | ||
with TemporaryDirectory() as tmp_dir: | ||
dataset.export(tmp_dir, 'datumaro', save_images=save_images) | ||
|
||
make_zip_archive(tmp_dir, dst_file) | ||
|
||
@importer(name="Datumaro 3D", ext="ZIP", version="1.0", dimension=DimensionType.DIM_3D) | ||
def _import(src_file, instance_data): | ||
with TemporaryDirectory() as tmp_dir: | ||
Archive(src_file.name).extractall(tmp_dir) | ||
|
||
dataset = Dataset.import_from(tmp_dir, 'datumaro', env=dm_env) | ||
|
||
import_dm_annotations(dataset, instance_data) |
Oops, something went wrong.
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.
Please check if the annotations do not include absolute image paths.
What about the format tests?
Also, think about loading tracks, if all the annotations have a
track_id
attribute.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.
Committed solution for problem with absolute image paths.
The format is tested along with all other formats in files:
test_formats.py
,test_rest_api_formats.py
.About tracks, I have a few thoughts:
track_id
attribute for all formats in theimport_dm_annotations
function (in other case we'll just duplicate similar code as for MOT format).How do you think which solution is better?
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.
The second solution looks better to me, but implementing it straight will cause unexpected side-effects. I think, we can try to add a common import option to import tracks, if possible. Not all formats will support this, of course, but those, that do, will utilize it. Not in this PR, though. MOT code is already duplicated with some adjustments in MOTS, btw, so I think the generic variant might be a bit complicated.