未验证 提交 c83d1700 编写于 作者: A AetherBreeze 提交者: GitHub

Add several flags to task_create CLI (#4119)

* Add serveral flags to CLI & generalize CLI code

definition.py:
	- Add use_zip_chunks, start_frame, stop_frame, and chunk_size
	  as CLI flags
	- Rename --bug to --bug_tracker to be consistent with website
	  and API
	- No longer include optional kwargs in all requests
core.py:
	- Add a single loop to handle all kwargs for extensibility
	- Lump optional task_create args into kwargs for brevity

* Add --bug as alias for --bug_tracker

- Add back old --bug flag for backwards compatability

* Update licence header

Update licence header for core.py

* Remove redundant parameter assignment

- Remove hardcoded `image_quality` default value, as this is already
  handled by the argparse default value.

* CHANGELOG entry for new CLI flags

* CLI linting fixes

- Several linting fixes for CLI

* Fix CLI test

- Re-add default image_quality in case task_create is called manually

* Resolve changelog merge conflict

* Update CHANGELOG.md
Co-authored-by: NAndrey Zhavoronkov <andrey.zhavoronkov@intel.com>
上级 e9c00cd9
...@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ...@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support for uploading manifest with any name (<https://github.com/openvinotoolkit/cvat/pull/4041>) - Support for uploading manifest with any name (<https://github.com/openvinotoolkit/cvat/pull/4041>)
- Added information about OpenVINO toolkit to login page (<https://github.com/openvinotoolkit/cvat/pull/4077>) - Added information about OpenVINO toolkit to login page (<https://github.com/openvinotoolkit/cvat/pull/4077>)
- Support for working with ellipses (<https://github.com/openvinotoolkit/cvat/pull/4062>) - Support for working with ellipses (<https://github.com/openvinotoolkit/cvat/pull/4062>)
- Add several flags to task creation CLI (<https://github.com/openvinotoolkit/cvat/pull/4119>)
### Changed ### Changed
- Users don't have access to a task object anymore if they are assigneed only on some jobs of the task (<https://github.com/openvinotoolkit/cvat/pull/3788>) - Users don't have access to a task object anymore if they are assigneed only on some jobs of the task (<https://github.com/openvinotoolkit/cvat/pull/3788>)
......
...@@ -34,19 +34,15 @@ class CLI(): ...@@ -34,19 +34,15 @@ class CLI():
data = {'remote_files[{}]'.format(i): f for i, f in enumerate(resources)} data = {'remote_files[{}]'.format(i): f for i, f in enumerate(resources)}
elif resource_type == ResourceType.SHARE: elif resource_type == ResourceType.SHARE:
data = {'server_files[{}]'.format(i): f for i, f in enumerate(resources)} data = {'server_files[{}]'.format(i): f for i, f in enumerate(resources)}
data['image_quality'] = 50 data['image_quality'] = 70
## capture additional kwargs ## capture additional kwargs
if 'image_quality' in kwargs: for flag in ['chunk_size', 'copy_data', 'image_quality', 'sorting_method',
data['image_quality'] = kwargs.get('image_quality') 'start_frame', 'stop_frame', 'use_cache', 'use_zip_chunks']:
if 'frame_step' in kwargs: if kwargs.get(flag) is not None:
data[flag] = kwargs.get(flag)
if kwargs.get('frame_step') is not None:
data['frame_filter'] = f"step={kwargs.get('frame_step')}" data['frame_filter'] = f"step={kwargs.get('frame_step')}"
if 'copy_data' in kwargs:
data['copy_data'] = kwargs.get('copy_data')
if 'use_cache' in kwargs:
data['use_cache'] = kwargs.get('use_cache')
if 'sorting_method' in kwargs:
data['sorting_method'] = kwargs.get('sorting_method')
response = self.session.post(url, data=data, files=files) response = self.session.post(url, data=data, files=files)
response.raise_for_status() response.raise_for_status()
...@@ -76,25 +72,24 @@ class CLI(): ...@@ -76,25 +72,24 @@ class CLI():
response.raise_for_status() response.raise_for_status()
return output return output
def tasks_create(self, name, labels, overlap, segment_size, bug, resource_type, resources, def tasks_create(self, name, labels, resource_type, resources,
annotation_path='', annotation_format='CVAT XML 1.1', annotation_path='', annotation_format='CVAT XML 1.1',
completion_verification_period=20, completion_verification_period=20,
git_completion_verification_period=2, git_completion_verification_period=2,
dataset_repository_url='', dataset_repository_url='',
project_id=None,
lfs=False, **kwargs): lfs=False, **kwargs):
""" Create a new task with the given name and labels JSON and """ Create a new task with the given name and labels JSON and
add the files to it. """ add the files to it. """
url = self.api.tasks url = self.api.tasks
labels = [] if project_id is not None else labels labels = [] if kwargs.get('project_id') is not None else labels
data = {'name': name, data = {'name': name,
'labels': labels, 'labels': labels
'overlap': overlap,
'segment_size': segment_size,
'bug_tracker': bug,
} }
if project_id:
data.update({'project_id': project_id}) for flag in ['bug_tracker', 'overlap', 'project_id', 'segment_size']:
if kwargs.get(flag) is not None:
data[flag] = kwargs.get(flag)
response = self.session.post(url, json=data) response = self.session.post(url, json=data)
response.raise_for_status() response.raise_for_status()
response_json = response.json() response_json = response.json()
......
# Copyright (C) 2021 Intel Corporation
#
# SPDX-License-Identifier: MIT # SPDX-License-Identifier: MIT
import argparse import argparse
import getpass import getpass
...@@ -106,36 +108,6 @@ task_create_parser.add_argument( ...@@ -106,36 +108,6 @@ task_create_parser.add_argument(
type=str, type=str,
help='name of the task' help='name of the task'
) )
task_create_parser.add_argument(
'--labels',
default='[]',
type=parse_label_arg,
help='string or file containing JSON labels specification'
)
task_create_parser.add_argument(
'--project_id',
default=None,
type=int,
help='project ID if project exists'
)
task_create_parser.add_argument(
'--overlap',
default=0,
type=int,
help='the number of intersected frames between different segments'
)
task_create_parser.add_argument(
'--segment_size',
default=0,
type=int,
help='the number of frames in a segment'
)
task_create_parser.add_argument(
'--bug',
default='',
type=str,
help='bug tracker URL'
)
task_create_parser.add_argument( task_create_parser.add_argument(
'resource_type', 'resource_type',
default='local', default='local',
...@@ -161,6 +133,18 @@ task_create_parser.add_argument( ...@@ -161,6 +133,18 @@ task_create_parser.add_argument(
type=str, type=str,
help='format of the annotation file being uploaded, e.g. CVAT 1.1' help='format of the annotation file being uploaded, e.g. CVAT 1.1'
) )
task_create_parser.add_argument(
'--bug_tracker', '--bug',
default=None,
type=str,
help='bug tracker URL'
)
task_create_parser.add_argument(
'--chunk_size',
default=None,
type=int,
help='the number of frames per chunk'
)
task_create_parser.add_argument( task_create_parser.add_argument(
'--completion_verification_period', '--completion_verification_period',
default=20, default=20,
...@@ -168,6 +152,13 @@ task_create_parser.add_argument( ...@@ -168,6 +152,13 @@ task_create_parser.add_argument(
help='''number of seconds to wait until checking help='''number of seconds to wait until checking
if data compression finished (necessary before uploading annotations)''' if data compression finished (necessary before uploading annotations)'''
) )
task_create_parser.add_argument(
'--copy_data',
default=False,
action='store_true',
help='''set the option to copy the data, only used when resource type is
share (default: %(default)s)'''
)
task_create_parser.add_argument( task_create_parser.add_argument(
'--dataset_repository_url', '--dataset_repository_url',
default='', default='',
...@@ -176,10 +167,11 @@ task_create_parser.add_argument( ...@@ -176,10 +167,11 @@ task_create_parser.add_argument(
' https://github.com/user/repos [annotation/<anno_file_name.zip>]') ' https://github.com/user/repos [annotation/<anno_file_name.zip>]')
) )
task_create_parser.add_argument( task_create_parser.add_argument(
'--lfs', '--frame_step',
default=False, default=None,
action='store_true', type=int,
help='using lfs for dataset repository (default: %(default)s)' help='''set the frame step option in the advanced configuration
when uploading image series or videos (default: %(default)s)'''
) )
task_create_parser.add_argument( task_create_parser.add_argument(
'--image_quality', '--image_quality',
...@@ -189,24 +181,34 @@ task_create_parser.add_argument( ...@@ -189,24 +181,34 @@ task_create_parser.add_argument(
when creating tasks.(default: %(default)s)''' when creating tasks.(default: %(default)s)'''
) )
task_create_parser.add_argument( task_create_parser.add_argument(
'--frame_step', '--labels',
default=1, default='[]',
type=int, type=parse_label_arg,
help='''set the frame step option in the advanced configuration help='string or file containing JSON labels specification'
when uploading image series or videos (default: %(default)s)'''
) )
task_create_parser.add_argument( task_create_parser.add_argument(
'--copy_data', '--lfs',
default=False, default=False,
action='store_true', action='store_true',
help='''set the option to copy the data, only used when resource type is help='using lfs for dataset repository (default: %(default)s)'
share (default: %(default)s)'''
) )
task_create_parser.add_argument( task_create_parser.add_argument(
'--use_cache', '--project_id',
default=True, default=None,
action='store_false', type=int,
help='''set the option to use the cache (default: %(default)s)''' help='project ID if project exists'
)
task_create_parser.add_argument(
'--overlap',
default=None,
type=int,
help='the number of intersected frames between different segments'
)
task_create_parser.add_argument(
'--segment_size',
default=None,
type=int,
help='the number of frames in a segment'
) )
task_create_parser.add_argument( task_create_parser.add_argument(
'--sorting-method', '--sorting-method',
...@@ -214,6 +216,28 @@ task_create_parser.add_argument( ...@@ -214,6 +216,28 @@ task_create_parser.add_argument(
choices=['lexicographical', 'natural', 'predefined', 'random'], choices=['lexicographical', 'natural', 'predefined', 'random'],
help='''data soring method (default: %(default)s)''' help='''data soring method (default: %(default)s)'''
) )
task_create_parser.add_argument(
'--start_frame',
default=None,
type=int,
help='the start frame of the video'
)
task_create_parser.add_argument(
'--stop_frame',
default=None,
type=int,
help='the stop frame of the video'
)
task_create_parser.add_argument(
'--use_cache',
action='store_true', # automatically sets default=False
help='''use cache'''
)
task_create_parser.add_argument(
'--use_zip_chunks',
action='store_true', # automatically sets default=False
help='''zip chunks before sending them to the server'''
)
####################################################################### #######################################################################
# Delete # Delete
......
...@@ -27,7 +27,6 @@ class TestCLI(APITestCase): ...@@ -27,7 +27,6 @@ class TestCLI(APITestCase):
self.taskname = 'test_task' self.taskname = 'test_task'
self.cli.tasks_create(self.taskname, self.cli.tasks_create(self.taskname,
[{'name' : 'car'}, {'name': 'person'}], [{'name' : 'car'}, {'name': 'person'}],
0, 0, '',
ResourceType.LOCAL, ResourceType.LOCAL,
[self.img_file]) [self.img_file])
# redirect logging to mocked stdout to test program output # redirect logging to mocked stdout to test program output
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册