[Datumaro] Add model info and source info commands (#1973)

* Add model info and source info commands

* update changelog

* adjust cli output
main
zhiltsov-max 6 years ago committed by GitHub
parent 953e3da4c9
commit 344b817b80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,7 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [1.1.0] - Unreleased
### Added
-
- [Datumaro] Added model info and source info commands (<https://github.com/opencv/cvat/pull/1973>)
### Changed
- Shape coordinates are rounded to 2 digits in dumped annotations (<https://github.com/opencv/cvat/pull/1970>)

@ -146,6 +146,30 @@ def run_command(args):
return 0
def build_info_parser(parser_ctor=argparse.ArgumentParser):
parser = parser_ctor()
parser.add_argument('-n', '--name',
help="Model name")
parser.add_argument('-v', '--verbose', action='store_true',
help="Show details")
parser.add_argument('-p', '--project', dest='project_dir', default='.',
help="Directory of the project to operate on (default: current dir)")
parser.set_defaults(command=info_command)
return parser
def info_command(args):
project = load_project(args.project_dir)
if args.name:
model = project.get_model(args.name)
print(model)
else:
for name, conf in project.config.models.items():
print(name)
if args.verbose:
print(dict(conf))
def build_parser(parser_ctor=argparse.ArgumentParser):
parser = parser_ctor()
@ -154,5 +178,6 @@ def build_parser(parser_ctor=argparse.ArgumentParser):
add_subparser(subparsers, 'add', build_add_parser)
add_subparser(subparsers, 'remove', build_remove_parser)
add_subparser(subparsers, 'run', build_run_parser)
add_subparser(subparsers, 'info', build_info_parser)
return parser

@ -55,7 +55,7 @@ def create_command(args):
if osp.isdir(project_env_dir) and os.listdir(project_env_dir):
if not args.overwrite:
raise CliException("Directory '%s' already exists "
"(pass --overwrite to force creation)" % project_env_dir)
"(pass --overwrite to overwrite)" % project_env_dir)
else:
shutil.rmtree(project_env_dir, ignore_errors=True)
@ -63,7 +63,7 @@ def create_command(args):
if osp.isdir(own_dataset_dir) and os.listdir(own_dataset_dir):
if not args.overwrite:
raise CliException("Directory '%s' already exists "
"(pass --overwrite to force creation)" % own_dataset_dir)
"(pass --overwrite to overwrite)" % own_dataset_dir)
else:
# NOTE: remove the dir to avoid using data from previous project
shutil.rmtree(own_dataset_dir)
@ -149,7 +149,7 @@ def import_command(args):
if osp.isdir(project_env_dir) and os.listdir(project_env_dir):
if not args.overwrite:
raise CliException("Directory '%s' already exists "
"(pass --overwrite to force creation)" % project_env_dir)
"(pass --overwrite to overwrite)" % project_env_dir)
else:
shutil.rmtree(project_env_dir, ignore_errors=True)
@ -157,7 +157,7 @@ def import_command(args):
if osp.isdir(own_dataset_dir) and os.listdir(own_dataset_dir):
if not args.overwrite:
raise CliException("Directory '%s' already exists "
"(pass --overwrite to force creation)" % own_dataset_dir)
"(pass --overwrite to overwrite)" % own_dataset_dir)
else:
# NOTE: remove the dir to avoid using data from previous project
shutil.rmtree(own_dataset_dir)
@ -328,7 +328,7 @@ def export_command(args):
if dst_dir:
if not args.overwrite and osp.isdir(dst_dir) and os.listdir(dst_dir):
raise CliException("Directory '%s' already exists "
"(pass --overwrite to force creation)" % dst_dir)
"(pass --overwrite to overwrite)" % dst_dir)
else:
dst_dir = generate_next_file_name('%s-%s' % \
(project.config.project_name, make_file_name(args.format)))
@ -424,7 +424,7 @@ def extract_command(args):
if dst_dir:
if not args.overwrite and osp.isdir(dst_dir) and os.listdir(dst_dir):
raise CliException("Directory '%s' already exists "
"(pass --overwrite to force creation)" % dst_dir)
"(pass --overwrite to overwrite)" % dst_dir)
else:
dst_dir = generate_next_file_name('%s-filter' % \
project.config.project_name)
@ -453,10 +453,10 @@ def extract_command(args):
return 0
def build_merge_parser(parser_ctor=argparse.ArgumentParser):
parser = parser_ctor(help="Merge projects",
parser = parser_ctor(help="Merge two projects",
description="""
Updates items of the current project with items
from the other project.|n
from other project.|n
|n
Examples:|n
- Update a project with items from other project:|n
@ -464,8 +464,8 @@ def build_merge_parser(parser_ctor=argparse.ArgumentParser):
""",
formatter_class=MultilineFormatter)
parser.add_argument('other_project_dir',
help="Directory of the project to get data updates from")
parser.add_argument('other_project',
help="Path to a project")
parser.add_argument('-o', '--output-dir', dest='dst_dir', default=None,
help="Output directory (default: current project's dir)")
parser.add_argument('--overwrite', action='store_true',
@ -484,11 +484,12 @@ def merge_command(args):
if dst_dir:
if not args.overwrite and osp.isdir(dst_dir) and os.listdir(dst_dir):
raise CliException("Directory '%s' already exists "
"(pass --overwrite to force creation)" % dst_dir)
"(pass --overwrite to overwrite)" % dst_dir)
first_dataset = first_project.make_dataset()
first_dataset.update(second_project.make_dataset())
second_dataset = second_project.make_dataset()
first_dataset.update(second_dataset)
first_dataset.save(save_dir=dst_dir)
if dst_dir is None:
@ -542,7 +543,7 @@ def diff_command(args):
if dst_dir:
if not args.overwrite and osp.isdir(dst_dir) and os.listdir(dst_dir):
raise CliException("Directory '%s' already exists "
"(pass --overwrite to force creation)" % dst_dir)
"(pass --overwrite to overwrite)" % dst_dir)
else:
dst_dir = generate_next_file_name('%s-%s-diff' % (
first_project.config.project_name,
@ -602,7 +603,7 @@ def transform_command(args):
if dst_dir:
if not args.overwrite and osp.isdir(dst_dir) and os.listdir(dst_dir):
raise CliException("Directory '%s' already exists "
"(pass --overwrite to force creation)" % dst_dir)
"(pass --overwrite to overwrite)" % dst_dir)
else:
dst_dir = generate_next_file_name('%s-%s' % \
(project.config.project_name, make_file_name(args.transform)))

@ -225,6 +225,31 @@ def remove_command(args):
return 0
def build_info_parser(parser_ctor=argparse.ArgumentParser):
parser = parser_ctor()
parser.add_argument('-n', '--name',
help="Source name")
parser.add_argument('-v', '--verbose', action='store_true',
help="Show details")
parser.add_argument('-p', '--project', dest='project_dir', default='.',
help="Directory of the project to operate on (default: current dir)")
parser.set_defaults(command=info_command)
return parser
def info_command(args):
project = load_project(args.project_dir)
if args.name:
source = project.get_source(args.name)
print(source)
else:
for name, conf in project.config.sources.items():
print(name)
if args.verbose:
print(dict(conf))
def build_parser(parser_ctor=argparse.ArgumentParser):
parser = parser_ctor(description="""
Manipulate data sources inside of a project.|n
@ -243,5 +268,6 @@ def build_parser(parser_ctor=argparse.ArgumentParser):
subparsers = parser.add_subparsers()
add_subparser(subparsers, 'add', build_add_parser)
add_subparser(subparsers, 'remove', build_remove_parser)
add_subparser(subparsers, 'info', build_info_parser)
return parser

Loading…
Cancel
Save