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

[Datumaro] Reducing nesting of tests #1875

Merged
merged 25 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
6082319
Added from_iterable method
KochankovID Jul 9, 2020
d94a0d3
Reduced tests nesting in test_coco_format.py
KochankovID Jul 9, 2020
34f8c47
Fixing Dangerous default value {} as argument
KochankovID Jul 9, 2020
a75e934
Try to fix Trailing whitespace
KochankovID Jul 9, 2020
7adf8a2
Try to fix Trailing whitespace (second try)
KochankovID Jul 9, 2020
75b2786
Fix comments and using existing code
KochankovID Jul 10, 2020
a7123bd
Fix tests considered with comment
KochankovID Jul 10, 2020
9a8464f
Rewrited coco tests
KochankovID Jul 10, 2020
a1a9583
Rewrited cvat tests
KochankovID Jul 10, 2020
ec822ec
Rewrite datumaro format
KochankovID Jul 10, 2020
dd39520
Added from_iterable to PointsCategories
KochankovID Jul 10, 2020
6d57c62
Rewrite some tests
KochankovID Jul 10, 2020
5471dda
Rewrite tests labelme
KochankovID Jul 10, 2020
215c010
Rewrite mot format
KochankovID Jul 10, 2020
03aa915
Rewrite tfrecord tests
KochankovID Jul 10, 2020
16130c3
rewrite transfors tests
KochankovID Jul 10, 2020
5cc94fa
Rewrite yolo tests
KochankovID Jul 11, 2020
ded422b
make reindex test great again
KochankovID Jul 11, 2020
47ae20f
adjust the indentation
KochankovID Jul 16, 2020
82d5241
added new fuctionality to Dataset.from_iterable()
KochankovID Jul 16, 2020
9a19190
rewrite tests
KochankovID Jul 16, 2020
c6089c9
Added comments, remove unnecessary comment
KochankovID Jul 17, 2020
6e045c6
Merge branch 'develop' into merged_tests
KochankovID Jul 17, 2020
f8a6456
fixing trailing
KochankovID Jul 17, 2020
9ee0017
fixed tests
KochankovID Jul 18, 2020
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
27 changes: 27 additions & 0 deletions datumaro/datumaro/components/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ def __eq__(self, other):
class LabelCategories(Categories):
Category = namedtuple('Category', ['name', 'parent', 'attributes'])

@classmethod
def from_iterable(cls, iterable):
zhiltsov-max marked this conversation as resolved.
Show resolved Hide resolved
temp_categories = cls()

if isinstance(iterable, str):
iterable = [[iterable]]

for category in iterable:
if isinstance(category, str):
category = [category]
temp_categories.add(*category)

return temp_categories

def __init__(self, items=None, attributes=None):
super().__init__(attributes=attributes)

Expand Down Expand Up @@ -482,6 +496,19 @@ def iou(self, other):
class PointsCategories(Categories):
Category = namedtuple('Category', ['labels', 'joints'])

@classmethod
def from_iterable(cls, iterable):
temp_categories = cls()

if isinstance(iterable, int):
iterable = [[iterable]]

for category in iterable:
if isinstance(category, int):
category = [category]
temp_categories.add(*category)
return temp_categories

def __init__(self, items=None, attributes=None):
super().__init__(attributes=attributes)

Expand Down
29 changes: 28 additions & 1 deletion datumaro/datumaro/components/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from datumaro.components.config import Config, DEFAULT_FORMAT
from datumaro.components.config_model import (Model, Source,
PROJECT_DEFAULT_CONFIG, PROJECT_SCHEMA)
from datumaro.components.extractor import Extractor
from datumaro.components.extractor import Extractor, LabelCategories
from datumaro.components.launcher import ModelTransform
from datumaro.components.dataset_filter import \
XPathDatasetFilter, XPathAnnotationsFilter
Expand Down Expand Up @@ -315,6 +315,33 @@ def categories(self):
return self._parent.categories()

class Dataset(Extractor):
@classmethod
def from_iterable(cls, iterable, categories=None):
"""Generation of Dataset from iterable object

Args:
iterable: Iterable object contains DatasetItems
categories (dict, optional): Dict of categories of datasets. Defaults to {}.

Returns:
Dataset: Dataset object
"""

if isinstance(categories, list):
categories = LabelCategories.from_iterable(categories)

if not categories:
categories = {}

class tmpExtractor(Extractor):
def __iter__(self):
return iter(iterable)

def categories(self):
return categories

return cls.from_extractors(tmpExtractor())

@classmethod
def from_extractors(cls, *sources):
# merge categories
Expand Down
Loading