@@ -58,15 +58,19 @@ def get_latest_annotations_for_video(self, video: Video) -> List[AnnotationScene
58
58
return annotation_scenes
59
59
60
60
def upload_annotations_for_video (
61
- self , video : Video , append_annotations : bool = False
61
+ self , video : Video , append_annotations : bool = False , max_threads : int = 5
62
62
):
63
63
"""
64
64
Upload annotations for a video. If append_annotations is set to True,
65
65
annotations will be appended to the existing annotations for the video in the
66
66
project. If set to False, existing annotations will be overwritten.
67
67
68
68
:param video: Video to upload annotations for
69
- :param append_annotations:
69
+ :param append_annotations: True to append annotations from the local disk to
70
+ the existing annotations on the server, False to overwrite the server
71
+ annotations by those on the local disk.
72
+ :param max_threads: Maximum number of threads to use for uploading. Defaults to 5.
73
+ Set to -1 to use all available threads.
70
74
:return:
71
75
"""
72
76
annotation_filenames = self .annotation_reader .get_data_filenames ()
@@ -83,27 +87,38 @@ def upload_annotations_for_video(
83
87
]
84
88
)
85
89
upload_count = self ._upload_annotations_for_2d_media_list (
86
- media_list = video_frames , append_annotations = append_annotations
90
+ media_list = video_frames ,
91
+ append_annotations = append_annotations ,
92
+ max_threads = max_threads ,
87
93
)
88
94
return upload_count
89
95
90
96
def upload_annotations_for_videos (
91
- self , videos : Sequence [Video ], append_annotations : bool = False
97
+ self ,
98
+ videos : Sequence [Video ],
99
+ append_annotations : bool = False ,
100
+ max_threads : int = 5 ,
92
101
):
93
102
"""
94
103
Upload annotations for a list of videos. If append_annotations is set to True,
95
104
annotations will be appended to the existing annotations for the video in the
96
105
project. If set to False, existing annotations will be overwritten.
97
106
98
107
:param videos: List of videos to upload annotations for
99
- :param append_annotations:
108
+ :param append_annotations: True to append annotations from the local disk to
109
+ the existing annotations on the server, False to overwrite the server
110
+ annotations by those on the local disk.
111
+ :param max_threads: Maximum number of threads to use for uploading. Defaults to 5.
112
+ Set to -1 to use all available threads.
100
113
:return:
101
114
"""
102
115
logging .info ("Starting video annotation upload..." )
103
116
upload_count = 0
104
117
for video in videos :
105
118
upload_count += self .upload_annotations_for_video (
106
- video = video , append_annotations = append_annotations
119
+ video = video ,
120
+ append_annotations = append_annotations ,
121
+ max_threads = max_threads ,
107
122
)
108
123
if upload_count > 0 :
109
124
logging .info (
@@ -113,20 +128,29 @@ def upload_annotations_for_videos(
113
128
logging .info ("No new video frame annotations were found." )
114
129
115
130
def upload_annotations_for_images (
116
- self , images : Sequence [Image ], append_annotations : bool = False
131
+ self ,
132
+ images : Sequence [Image ],
133
+ append_annotations : bool = False ,
134
+ max_threads : int = 5 ,
117
135
):
118
136
"""
119
137
Upload annotations for a list of images. If append_annotations is set to True,
120
138
annotations will be appended to the existing annotations for the image in the
121
139
project. If set to False, existing annotations will be overwritten.
122
140
123
141
:param images: List of images to upload annotations for
124
- :param append_annotations:
142
+ :param append_annotations: True to append annotations from the local disk to
143
+ the existing annotations on the server, False to overwrite the server
144
+ annotations by those on the local disk.
145
+ :param max_threads: Maximum number of threads to use for uploading. Defaults to 5.
146
+ Set to -1 to use all available threads.
125
147
:return:
126
148
"""
127
149
logging .info ("Starting image annotation upload..." )
128
150
upload_count = self ._upload_annotations_for_2d_media_list (
129
- media_list = images , append_annotations = append_annotations
151
+ media_list = images ,
152
+ append_annotations = append_annotations ,
153
+ max_threads = max_threads ,
130
154
)
131
155
if upload_count > 0 :
132
156
logging .info (
@@ -271,7 +295,9 @@ def download_all_annotations(
271
295
max_threads = max_threads ,
272
296
)
273
297
274
- def upload_annotations_for_all_media (self , append_annotations : bool = False ):
298
+ def upload_annotations_for_all_media (
299
+ self , append_annotations : bool = False , max_threads : int = 5
300
+ ):
275
301
"""
276
302
Upload annotations for all media in the project, If append_annotations is set
277
303
to True, annotations will be appended to the existing annotations for the
@@ -280,16 +306,22 @@ def upload_annotations_for_all_media(self, append_annotations: bool = False):
280
306
:param append_annotations: True to append annotations from the local disk to
281
307
the existing annotations on the server, False to overwrite the server
282
308
annotations by those on the local disk. Defaults to False.
309
+ :param max_threads: Maximum number of threads to use for uploading. Defaults to 5.
310
+ Set to -1 to use all available threads.
283
311
"""
284
312
image_list = self ._get_all_media_by_type (media_type = Image )
285
313
video_list = self ._get_all_media_by_type (media_type = Video )
286
314
if len (image_list ) > 0 :
287
315
self .upload_annotations_for_images (
288
- images = image_list , append_annotations = append_annotations
316
+ images = image_list ,
317
+ append_annotations = append_annotations ,
318
+ max_threads = max_threads ,
289
319
)
290
320
if len (video_list ) > 0 :
291
321
self .upload_annotations_for_videos (
292
- videos = video_list , append_annotations = append_annotations
322
+ videos = video_list ,
323
+ append_annotations = append_annotations ,
324
+ max_threads = max_threads ,
293
325
)
294
326
295
327
def upload_annotation (
0 commit comments