Skip to content

Commit 09d97a0

Browse files
zhiltsov-maxChris Lee-Messer
authored and
Chris Lee-Messer
committed
[Datumaro] VOC labelmap support (cvat-ai#957)
* Add import result checks and options to skip * Add label-specific attributes * Overwrite option for export * Add labelmap file support in voc * Add labelmap tests * Little refactoring
1 parent cbcdc21 commit 09d97a0

File tree

8 files changed

+576
-220
lines changed

8 files changed

+576
-220
lines changed

datumaro/datumaro/cli/project/__init__.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ def build_import_parser(parser):
6868
help="Overwrite existing files in the save directory")
6969
parser.add_argument('--copy', action='store_true',
7070
help="Copy the dataset instead of saving source links")
71+
parser.add_argument('--skip-check', action='store_true',
72+
help="Skip source checking")
7173
# parser.add_argument('extra_args', nargs=argparse.REMAINDER,
7274
# help="Additional arguments for importer (pass '-- -h' for help)")
7375
return parser
@@ -99,7 +101,9 @@ def import_command(args):
99101
project.config.project_name = project_name
100102
project.config.project_dir = project_dir
101103

102-
dataset = project.make_dataset()
104+
if not args.skip_check or args.copy:
105+
log.info("Checking the dataset...")
106+
dataset = project.make_dataset()
103107
if args.copy:
104108
log.info("Cloning data...")
105109
dataset.save(merge=True, save_images=True)
@@ -127,6 +131,8 @@ def build_export_parser(parser):
127131
help="Output format")
128132
parser.add_argument('-p', '--project', dest='project_dir', default='.',
129133
help="Directory of the project to operate on (default: current dir)")
134+
parser.add_argument('--overwrite', action='store_true',
135+
help="Overwrite existing files in the save directory")
130136
parser.add_argument('extra_args', nargs=argparse.REMAINDER, default=None,
131137
help="Additional arguments for converter (pass '-- -h' for help)")
132138
return parser
@@ -135,7 +141,11 @@ def export_command(args):
135141
project = load_project(args.project_dir)
136142

137143
dst_dir = osp.abspath(args.dst_dir)
138-
os.makedirs(dst_dir, exist_ok=False)
144+
if not args.overwrite and osp.isdir(dst_dir) and os.listdir(dst_dir):
145+
log.error("Directory '%s' already exists "
146+
"(pass --overwrite to force creation)" % dst_dir)
147+
return 1
148+
os.makedirs(dst_dir, exist_ok=args.overwrite)
139149

140150
project.make_dataset().export(
141151
save_dir=dst_dir,

datumaro/datumaro/cli/source/__init__.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,16 @@ def build_import_parser(parser):
6262
dir_parser.add_argument('url',
6363
help="Path to the source directory")
6464
dir_parser.add_argument('--copy', action='store_true',
65-
help="Copy data to the project")
65+
help="Copy the dataset instead of saving source links")
6666

67+
parser.add_argument('-n', '--name', default=None,
68+
help="Name of the new source")
6769
parser.add_argument('-f', '--format', default=None,
6870
help="Name of the source dataset format (default: 'project')")
69-
parser.add_argument('-n', '--name', default=None,
70-
help="Name of the source to be imported")
7171
parser.add_argument('-p', '--project', dest='project_dir', default='.',
7272
help="Directory of the project to operate on (default: current dir)")
73+
parser.add_argument('--skip-check', action='store_true',
74+
help="Skip source checking")
7375
return parser
7476

7577
def import_command(args):
@@ -99,6 +101,10 @@ def import_command(args):
99101
if args.format:
100102
source['format'] = args.format
101103
project.add_source(name, source)
104+
105+
if not args.skip_check:
106+
log.info("Checking the source...")
107+
project.make_source_project(name)
102108
project.save()
103109

104110
log.info("Source '%s' has been added to the project, location: '%s'" \
@@ -131,6 +137,10 @@ def import_command(args):
131137
if args.format:
132138
source['format'] = args.format
133139
project.add_source(name, source)
140+
141+
if not args.skip_check:
142+
log.info("Checking the source...")
143+
project.make_source_project(name)
134144
project.save()
135145

136146
log.info("Source '%s' has been added to the project, location: '%s'" \
@@ -184,6 +194,8 @@ def build_export_parser(parser):
184194
help="Output format")
185195
parser.add_argument('-p', '--project', dest='project_dir', default='.',
186196
help="Directory of the project to operate on (default: current dir)")
197+
parser.add_argument('--overwrite', action='store_true',
198+
help="Overwrite existing files in the save directory")
187199
parser.add_argument('extra_args', nargs=argparse.REMAINDER, default=None,
188200
help="Additional arguments for converter (pass '-- -h' for help)")
189201
return parser
@@ -192,7 +204,11 @@ def export_command(args):
192204
project = load_project(args.project_dir)
193205

194206
dst_dir = osp.abspath(args.dst_dir)
195-
os.makedirs(dst_dir, exist_ok=False)
207+
if not args.overwrite and osp.isdir(dst_dir) and os.listdir(dst_dir):
208+
log.error("Directory '%s' already exists "
209+
"(pass --overwrite to force creation)" % dst_dir)
210+
return 1
211+
os.makedirs(dst_dir, exist_ok=args.overwrite)
196212

197213
source_project = project.make_source_project(args.name)
198214
source_project.make_dataset().export(

0 commit comments

Comments
 (0)