Skip to content

Commit

Permalink
Functionality to upload annotations on task creation (#1735)
Browse files Browse the repository at this point in the history
* Upload annotations on task creation

* Bulk upload v1

* Not working

* Annotation upon task creation finished

* Functionality to upload annotations on task creation

* Functionality to upload annotations on task creation

* Functionality to upload annotations on task creation

* Functionality to upload annotations on task creation

* Fix trailing whitespace

* Use status request for checking task completion

* fixed default format name

Co-authored-by: Eric Grinstein <v-ergri@microsoft.com>
Co-authored-by: Andrey Zhavoronkov <andrey.zhavoronkov@intel.com>
Co-authored-by: Nikita Manovich <40690625+nmanovic@users.noreply.github.com>
  • Loading branch information
4 people authored Jun 22, 2020
1 parent 90c8f78 commit 3fee4cf
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Built-in search for labels when create an object or change a label (<https://github.com/opencv/cvat/pull/1683>)
- Better validation of labels and attributes in raw viewer (<https://github.com/opencv/cvat/pull/1727>)
- ClamAV antivirus integration (<https://github.com/opencv/cvat/pull/1712>)
- Add option to upload annotations upon task creation on CLI
- Polygon and polylines interpolation (<https://github.com/opencv/cvat/pull/1571>)
- Ability to redraw shape from scratch (Shift + N) for an activated shape (<https://github.com/opencv/cvat/pull/1571>)
- Highlights for the first point of a polygon/polyline and direction (<https://github.com/opencv/cvat/pull/1571>)
Expand Down
33 changes: 29 additions & 4 deletions utils/cli/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import requests
from io import BytesIO
import mimetypes
from time import sleep

from PIL import Image

Expand Down Expand Up @@ -57,7 +58,9 @@ def tasks_list(self, use_json_output, **kwargs):
response = self.session.get(url)
response.raise_for_status()

def tasks_create(self, name, labels, bug, resource_type, resources, **kwargs):
def tasks_create(self, name, labels, bug, resource_type, resources,
annotation_path='', annotation_format='CVAT XML 1.1',
completion_verification_period=20, **kwargs):
""" Create a new task with the given name and labels JSON and
add the files to it. """
url = self.api.tasks
Expand All @@ -69,7 +72,26 @@ def tasks_create(self, name, labels, bug, resource_type, resources, **kwargs):
response.raise_for_status()
response_json = response.json()
log.info('Created task ID: {id} NAME: {name}'.format(**response_json))
self.tasks_data(response_json['id'], resource_type, resources)
task_id = response_json['id']
self.tasks_data(task_id, resource_type, resources)

if annotation_path != '':
url = self.api.tasks_id_status(task_id)
response = self.session.get(url)
response_json = response.json()

log.info('Awaiting data compression before uploading annotations...')
while response_json['state'] != 'Finished':
sleep(completion_verification_period)
response = self.session.get(url)
response_json = response.json()
logger_string= '''Awaiting compression for task {}.
Status={}, Message={}'''.format(task_id,
response_json['state'],
response_json['message'])
log.info(logger_string)

self.tasks_upload(task_id, annotation_format, annotation_path, **kwargs)

def tasks_delete(self, task_ids, **kwargs):
""" Delete a list of tasks, ignoring those which don't exist. """
Expand Down Expand Up @@ -135,8 +157,8 @@ def tasks_upload(self, task_id, fileformat, filename, **kwargs):
while True:
response = self.session.put(
url,
files={'annotation_file':open(filename, 'rb')}
)
files={'annotation_file': open(filename, 'rb')}
)
response.raise_for_status()
if response.status_code == 201:
break
Expand Down Expand Up @@ -176,6 +198,9 @@ def tasks_id_data(self, task_id):
def tasks_id_frame_id(self, task_id, frame_id, quality):
return self.tasks_id(task_id) + '/data?type=frame&number={}&quality={}'.format(frame_id, quality)

def tasks_id_status(self, task_id):
return self.tasks_id(task_id) + '/status'

def tasks_id_annotations_format(self, task_id, fileformat):
return self.tasks_id(task_id) + '/annotations?format={}' \
.format(fileformat)
Expand Down
21 changes: 20 additions & 1 deletion utils/cli/core/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,25 @@ def argparse(s):
help='list of paths or URLs',
nargs='+'
)
task_create_parser.add_argument(
'--annotation_path',
default='',
type=str,
help='path to annotation file'
)
task_create_parser.add_argument(
'--annotation_format',
default='CVAT 1.1',
type=str,
help='format of the annotation file being uploaded, e.g. CVAT 1.1'
)
task_create_parser.add_argument(
'--completion_verification_period',
default=20,
type=int,
help='''number of seconds to wait until checking
if data compression finished (necessary before uploading annotations)'''
)

#######################################################################
# Delete
Expand Down Expand Up @@ -240,4 +259,4 @@ def argparse(s):
type=str,
default='CVAT 1.1',
help='annotation format (default: %(default)s)'
)
)

0 comments on commit 3fee4cf

Please sign in to comment.