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

Add test code for cli upload function #986

Merged
merged 4 commits into from
Dec 24, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
add upload annotation function to cli
  • Loading branch information
neo committed Dec 15, 2019
commit 6cabe4d30a38e905b370fe072d0f3f3a874f1687
3 changes: 2 additions & 1 deletion utils/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ def main():
'delete': CLI.tasks_delete,
'ls': CLI.tasks_list,
'frames': CLI.tasks_frame,
'dump': CLI.tasks_dump}
'dump': CLI.tasks_dump,
'upload': CLI.tasks_upload}
args = parser.parse_args()
config_log(args.loglevel)
with requests.Session() as session:
Expand Down
20 changes: 20 additions & 0 deletions utils/cli/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,22 @@ def tasks_dump(self, task_id, fileformat, filename, **kwargs):
with open(filename, 'wb') as fp:
fp.write(response.content)

def tasks_upload(self, task_id, fileformat, filename, **kwargs):
""" Upload annotations for a task in the specified format
(e.g. 'YOLO ZIP 1.0')."""
url = self.api.tasks_id_annotations_format(task_id, fileformat)
while True:
response = self.session.put(
url,
files={'annotation_file':open(filename, 'rb')}
)
response.raise_for_status()
if response.status_code == 201:
break

log.info('Upload job for Task ID {} \
with annotation file {} finished'.format(task_id, filename))


class CVAT_API_V1():
""" Build parameterized API URLs """
Expand All @@ -135,6 +151,10 @@ def tasks_id_data(self, task_id):
def tasks_id_frame_id(self, task_id, frame_id):
return self.tasks_id(task_id) + '/frames/{}'.format(frame_id)

def tasks_id_annotations_format(self, task_id, fileformat):
return self.tasks_id(task_id) + '/annotations?format={}' \
.format(fileformat)

def tasks_id_annotations_filename(self, task_id, name, fileformat):
return self.tasks_id(task_id) + '/annotations/{}?format={}' \
.format(name, fileformat)
26 changes: 26 additions & 0 deletions utils/cli/core/definition.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,29 @@ def argparse(s):
default='CVAT XML 1.1 for images',
help='annotation format (default: %(default)s)'
)

#######################################################################
# Upload Annotations
#######################################################################

upload_parser = task_subparser.add_parser(
'upload',
description='Upload annotations for a CVAT task.'
)
upload_parser.add_argument(
'task_id',
type=int,
help='task ID'
)
upload_parser.add_argument(
'filename',
type=str,
help='upload file'
)
upload_parser.add_argument(
'--format',
dest='fileformat',
type=str,
default='CVAT XML 1.1',
help='annotation format (default: %(default)s)'
)