From 61e112e2f299408401a98ecd21c2f4abb78c0106 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Aquilina?= <32460579+dreaquil@users.noreply.github.com> Date: Tue, 30 Mar 2021 13:26:34 +0100 Subject: [PATCH] Add dataset URI to Task from CLI (#2983) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add option to include git repository for annotation synchronisation. * Add arge parser for git dataset repository in task create. * Update changelog. * Add API for git. * Add verification procedure for dataset repository creation. Co-authored-by: André Aquilina --- CHANGELOG.md | 1 + utils/cli/core/core.py | 35 ++++++++++++++++++++++++++++++++++- utils/cli/core/definition.py | 14 +++++++++++++- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 97c021e0..8e6f3488 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added +- CLI: Add support for saving annotations in a git repository when creating a task. - CVAT-3D: support lidar data on the server side () - GPU support for Mask-RCNN and improvement in its deployment time () - CVAT-3D: Load all frames corresponding to the job instance diff --git a/utils/cli/core/core.py b/utils/cli/core/core.py index 0fc76c9a..57b39d1f 100644 --- a/utils/cli/core/core.py +++ b/utils/cli/core/core.py @@ -63,7 +63,10 @@ class CLI(): def tasks_create(self, name, labels, overlap, segment_size, bug, resource_type, resources, annotation_path='', annotation_format='CVAT XML 1.1', - completion_verification_period=20, **kwargs): + completion_verification_period=20, + git_completion_verification_period=2, + dataset_repository_url='', + lfs=False, **kwargs): """ Create a new task with the given name and labels JSON and add the files to it. """ url = self.api.tasks @@ -97,6 +100,29 @@ class CLI(): log.info(logger_string) self.tasks_upload(task_id, annotation_format, annotation_path, **kwargs) + if dataset_repository_url: + response = self.session.post( + self.api.git_create(task_id), + json={ + 'path': dataset_repository_url, + 'lfs': lfs, + 'tid': task_id}) + response_json = response.json() + rq_id = response_json['rq_id'] + log.info(f"Create RQ ID: {rq_id}") + check_url = self.api.git_check(rq_id) + response = self.session.get(check_url) + response_json = response.json() + log.info('''Awaiting dataset repository for task. Status: {}'''.format( + response_json['status'])) + while response_json['status'] != 'finished': + sleep(git_completion_verification_period) + response = self.session.get(check_url) + response_json = response.json() + if response_json['status'] == 'Failed': + log.error(f'Dataset repository creation request for task {task_id} failed.') + + log.info(f"Dataset repository creation completed with status: {response_json['status']}.") def tasks_delete(self, task_ids, **kwargs): """ Delete a list of tasks, ignoring those which don't exist. """ @@ -192,6 +218,7 @@ class CVAT_API_V1(): host = host.replace('https://', '') scheme = 'https' if https else 'http' self.base = '{}://{}/api/v1/'.format(scheme, host) + self.git = f'{scheme}://{host}/git/repository/' @property def tasks(self): @@ -220,6 +247,12 @@ class CVAT_API_V1(): return self.tasks_id(task_id) + '/annotations?format={}&filename={}' \ .format(fileformat, name) + def git_create(self, task_id): + return self.git + f'create/{task_id}' + + def git_check(self, rq_id): + return self.git + f'check/{rq_id}' + @property def login(self): return self.base + 'auth/login' diff --git a/utils/cli/core/definition.py b/utils/cli/core/definition.py index c30eae07..c15dbafe 100644 --- a/utils/cli/core/definition.py +++ b/utils/cli/core/definition.py @@ -162,7 +162,19 @@ task_create_parser.add_argument( help='''number of seconds to wait until checking if data compression finished (necessary before uploading annotations)''' ) - +task_create_parser.add_argument( + '--dataset_repository_url', + default='', + type=str, + help=('git repository to store annotations e.g.' + ' https://github.com/user/repos [annotation/]') +) +task_create_parser.add_argument( + '--lfs', + default=False, + action='store_true', + help='using lfs for dataset repository (default: %(default)s)' +) ####################################################################### # Delete #######################################################################