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

Readable COCO and datumaro format for CJK #307

Merged
merged 4 commits into from
Jun 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions datumaro/plugins/coco_format/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def write(self, path):
next_id += 1

with open(path, 'w') as outfile:
zhiltsov-max marked this conversation as resolved.
Show resolved Hide resolved
json.dump(self._data, outfile)
json.dump(self._data, outfile, ensure_ascii=False)

@property
def annotations(self):
Expand Down Expand Up @@ -462,7 +462,7 @@ class _StuffConverter(_InstancesConverter):
class _PanopticConverter(_TaskConverter):
def write(self, path):
with open(path, 'w') as outfile:
zhiltsov-max marked this conversation as resolved.
Show resolved Hide resolved
json.dump(self._data, outfile)
json.dump(self._data, outfile, ensure_ascii=False)

def save_categories(self, dataset):
label_categories = dataset.categories().get(AnnotationType.label)
Expand Down
2 changes: 1 addition & 1 deletion datumaro/plugins/datumaro_format/converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def write_categories(self, categories):

def write(self, save_dir):
with open(osp.join(save_dir, '%s.json' % self._name), 'w') as f:
zhiltsov-max marked this conversation as resolved.
Show resolved Hide resolved
json.dump(self._data, f)
json.dump(self._data, f, ensure_ascii=False)

def _convert_annotation(self, obj):
assert isinstance(obj, Annotation)
Expand Down
1 change: 1 addition & 0 deletions tests/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class Requirements:

# GitHub issues (not bugs)
# https://github.com/openvinotoolkit/datumaro/issues
DATUM_231 = "Readable formats for CJK"
DATUM_244 = "Add Snyk integration"
DATUM_267 = "Add Image zip format"
DATUM_280 = "Support KITTI dataset formats"
Expand Down
30 changes: 30 additions & 0 deletions tests/test_coco_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,36 @@ def test_can_save_and_load_images(self):
self._test_save_and_load(expected_dataset,
CocoImageInfoConverter.convert, test_dir)

@mark_requirement(Requirements.DATUM_231)
def test_can_save_dataset_with_cjk_categories(self):
expected_dataset = Dataset.from_iterable([
DatasetItem(id=1, subset='train', image=np.ones((4, 4, 3)),
annotations=[
Bbox(0, 1, 2, 2,
label=0, group=1, id=1,
attributes={ 'is_crowd': False }),
], attributes={'id': 1}),
DatasetItem(id=2, subset='train', image=np.ones((4, 4, 3)),
annotations=[
Bbox(1, 0, 2, 2, label=1, group=2, id=2,
attributes={ 'is_crowd': False }),
], attributes={'id': 2}),

DatasetItem(id=3, subset='train', image=np.ones((4, 4, 3)),
annotations=[
Bbox(0, 1, 2, 2, label=2, group=3, id=3,
attributes={ 'is_crowd': False }),
], attributes={'id': 3}),
],
categories=[
"고양이", "ネコ", "猫"
]
)

with TestDir() as test_dir:
self._test_save_and_load(expected_dataset,
CocoInstancesConverter.convert, test_dir)

@mark_requirement(Requirements.DATUM_GENERAL_REQ)
def test_can_save_dataset_with_cyrillic_and_spaces_in_filename(self):
expected_dataset = Dataset.from_iterable([
Expand Down
31 changes: 31 additions & 0 deletions tests/test_datumaro_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,37 @@ def test_relative_paths(self):
self._test_save_and_load(test_dataset,
partial(DatumaroConverter.convert, save_images=True), test_dir)


@mark_requirement(Requirements.DATUM_231)
def test_can_save_dataset_with_cjk_categories(self):
expected = Dataset.from_iterable([
DatasetItem(id=1, subset='train', image=np.ones((4, 4, 3)),
annotations=[
Bbox(0, 1, 2, 2,
label=0, group=1, id=1,
attributes={ 'is_crowd': False }),
], attributes={'id': 1}),
DatasetItem(id=2, subset='train', image=np.ones((4, 4, 3)),
annotations=[
Bbox(1, 0, 2, 2, label=1, group=2, id=2,
attributes={ 'is_crowd': False }),
], attributes={'id': 2}),

DatasetItem(id=3, subset='train', image=np.ones((4, 4, 3)),
annotations=[
Bbox(0, 1, 2, 2, label=2, group=3, id=3,
attributes={ 'is_crowd': False }),
], attributes={'id': 3}),
],
categories=[
"고양이", "ネコ", "猫"
]
)

with TestDir() as test_dir:
self._test_save_and_load(expected,
partial(DatumaroConverter.convert, save_images=True), test_dir)

@mark_requirement(Requirements.DATUM_GENERAL_REQ)
def test_can_save_dataset_with_cyrillic_and_spaces_in_filename(self):
test_dataset = Dataset.from_iterable([
Expand Down