Skip to content

Commit

Permalink
[Datumaro] VOC labelmap support (#957)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
zhiltsov-max authored and nmanovic committed Dec 17, 2019
1 parent 20a0e66 commit c84daaf
Show file tree
Hide file tree
Showing 8 changed files with 576 additions and 220 deletions.
14 changes: 12 additions & 2 deletions datumaro/datumaro/cli/project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def build_import_parser(parser):
help="Overwrite existing files in the save directory")
parser.add_argument('--copy', action='store_true',
help="Copy the dataset instead of saving source links")
parser.add_argument('--skip-check', action='store_true',
help="Skip source checking")
# parser.add_argument('extra_args', nargs=argparse.REMAINDER,
# help="Additional arguments for importer (pass '-- -h' for help)")
return parser
Expand Down Expand Up @@ -99,7 +101,9 @@ def import_command(args):
project.config.project_name = project_name
project.config.project_dir = project_dir

dataset = project.make_dataset()
if not args.skip_check or args.copy:
log.info("Checking the dataset...")
dataset = project.make_dataset()
if args.copy:
log.info("Cloning data...")
dataset.save(merge=True, save_images=True)
Expand Down Expand Up @@ -127,6 +131,8 @@ def build_export_parser(parser):
help="Output format")
parser.add_argument('-p', '--project', dest='project_dir', default='.',
help="Directory of the project to operate on (default: current dir)")
parser.add_argument('--overwrite', action='store_true',
help="Overwrite existing files in the save directory")
parser.add_argument('extra_args', nargs=argparse.REMAINDER, default=None,
help="Additional arguments for converter (pass '-- -h' for help)")
return parser
Expand All @@ -135,7 +141,11 @@ def export_command(args):
project = load_project(args.project_dir)

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

project.make_dataset().export(
save_dir=dst_dir,
Expand Down
24 changes: 20 additions & 4 deletions datumaro/datumaro/cli/source/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@ def build_import_parser(parser):
dir_parser.add_argument('url',
help="Path to the source directory")
dir_parser.add_argument('--copy', action='store_true',
help="Copy data to the project")
help="Copy the dataset instead of saving source links")

parser.add_argument('-n', '--name', default=None,
help="Name of the new source")
parser.add_argument('-f', '--format', default=None,
help="Name of the source dataset format (default: 'project')")
parser.add_argument('-n', '--name', default=None,
help="Name of the source to be imported")
parser.add_argument('-p', '--project', dest='project_dir', default='.',
help="Directory of the project to operate on (default: current dir)")
parser.add_argument('--skip-check', action='store_true',
help="Skip source checking")
return parser

def import_command(args):
Expand Down Expand Up @@ -99,6 +101,10 @@ def import_command(args):
if args.format:
source['format'] = args.format
project.add_source(name, source)

if not args.skip_check:
log.info("Checking the source...")
project.make_source_project(name)
project.save()

log.info("Source '%s' has been added to the project, location: '%s'" \
Expand Down Expand Up @@ -131,6 +137,10 @@ def import_command(args):
if args.format:
source['format'] = args.format
project.add_source(name, source)

if not args.skip_check:
log.info("Checking the source...")
project.make_source_project(name)
project.save()

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

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

source_project = project.make_source_project(args.name)
source_project.make_dataset().export(
Expand Down
Loading

0 comments on commit c84daaf

Please sign in to comment.