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

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

Merged
merged 4 commits into from
Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-
Expand Down
25 changes: 25 additions & 0 deletions datumaro/datumaro/cli/contexts/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
29 changes: 15 additions & 14 deletions datumaro/datumaro/cli/contexts/project/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ 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)

own_dataset_dir = osp.join(project_dir, DEFAULT_CONFIG.dataset_dir)
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)
Expand Down Expand Up @@ -149,15 +149,15 @@ 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)

own_dataset_dir = osp.join(project_dir, DEFAULT_CONFIG.dataset_dir)
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)
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -453,19 +453,19 @@ 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
|s|smerge -p path/to/first/project path/to/other/project
""",
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',
Expand All @@ -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:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)))
Expand Down
26 changes: 26 additions & 0 deletions datumaro/datumaro/cli/contexts/source/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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