Skip to content

Commit a14752b

Browse files
author
Maxim Zhiltsov
committed
Add a test for failing export with a reserved subset name
1 parent d7a13fb commit a14752b

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3838
(<https://github.com/openvinotoolkit/datumaro/pull/684>,
3939
<https://github.com/openvinotoolkit/datumaro/pull/686>,
4040
<https://github.com/openvinotoolkit/datumaro/pull/687>)
41-
- YOLO format now supports almost any subset names, except of
42-
just `train` and `valid`
41+
- YOLO format now supports almost any subset names, except `backup`, `names` and `classes`
42+
(instead of just `train` and `valid`). The reserved names now raise an error on exporting.
4343
(<https://github.com/openvinotoolkit/datumaro/pull/688>)
4444

4545
### Deprecated

datumaro/plugins/yolo_format/converter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def apply(self):
7777
subset_name = YoloPath.DEFAULT_SUBSET_NAME
7878
elif subset_name in YoloPath.RESERVED_CONFIG_KEYS:
7979
raise DatasetExportError(
80-
f"Can't export '{subset_name}' subset in YOLO format, this word " "is reserved."
80+
f"Can't export '{subset_name}' subset in YOLO format, this word is reserved."
8181
)
8282

8383
subset_dir = osp.join(save_dir, "obj_%s_data" % subset_name)

site/content/en/docs/formats/yolo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Supported annotation types:
1818

1919
YOLO format doesn't support attributes for annotations.
2020

21-
The format supports arbitrary subset names, except `classes` and `backup`.
21+
The format supports arbitrary subset names, except `classes`, `names` and `backup`.
2222

2323
> Note, that by default, the YOLO framework does not expect any subset names,
2424
except `train` and `valid`, Datumaro supports this as an extension.

tests/test_yolo_format.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from datumaro.components.environment import Environment
1111
from datumaro.components.errors import (
1212
AnnotationImportError,
13+
DatasetExportError,
1314
DatasetImportError,
1415
InvalidAnnotationError,
1516
ItemImportError,
@@ -285,6 +286,25 @@ def test_can_save_and_load_with_custom_subset_name(self):
285286

286287
compare_datasets(self, source_dataset, parsed_dataset)
287288

289+
@mark_requirement(Requirements.DATUM_565)
290+
def test_cant_save_with_reserved_subset_name(self):
291+
for subset in ["backup", "classes"]:
292+
293+
dataset = Dataset.from_iterable(
294+
[
295+
DatasetItem(
296+
id=3,
297+
subset=subset,
298+
media=Image(data=np.ones((8, 8, 3))),
299+
),
300+
],
301+
categories=["a"],
302+
)
303+
304+
with TestDir() as test_dir:
305+
with self.assertRaisesRegex(DatasetExportError, f"Can't export '{subset}' subset"):
306+
YoloConverter.convert(dataset, test_dir)
307+
288308
@mark_requirement(Requirements.DATUM_609)
289309
def test_can_save_and_load_without_path_prefix(self):
290310
source_dataset = Dataset.from_iterable(

0 commit comments

Comments
 (0)