@@ -189,16 +189,55 @@ def download_from_cvat(self, max_retry_count=5, retry_wait_time=10):
189
189
task_id , task_name = self .get_cvat_task_id (project_id , create = False )
190
190
logger .info (f"Preparing to download/update final labels from: { project_id } => { task_id } => { task_name } " )
191
191
192
- download_url = f"{ self .api_url } /api/tasks/{ task_id } /annotations?action=download&format=Segmentation+mask+1.1"
192
+ # Step 1: Initiate export process
193
+ export_url = f"{ self .api_url } /api/tasks/{ task_id } /dataset/export?format=Segmentation+mask+1.1&location=local&save_images=false"
194
+ try :
195
+ response = requests .post (export_url , auth = self .auth )
196
+ if response .status_code not in [200 , 202 ]:
197
+ logger .error (f"Failed to initiate export process: { response .status_code } , { response .text } " )
198
+ return None
199
+
200
+ rq_id = response .json ().get ("rq_id" )
201
+ if not rq_id :
202
+ logger .error ("Export process did not return a request ID (rq_id)." )
203
+ return None
204
+ logger .info (f"Export process initiated successfully with request ID: { rq_id } " )
205
+ except Exception as e :
206
+ logger .exception (f"Error while initiating export process: { e } " )
207
+ return None
208
+
209
+ # Step 2: Poll export status
210
+ status_url = f"{ self .api_url } /api/requests/{ rq_id } "
211
+ for _ in range (max_retry_count ):
212
+ try :
213
+ status_response = requests .get (status_url , auth = self .auth )
214
+ status = status_response .json ().get ("status" )
215
+ if status == "finished" :
216
+ logger .info ("Export process completed successfully." )
217
+ break
218
+ elif status == "failed" :
219
+ logger .error (f"Export process failed: { status_response .json ()} " )
220
+ return None
221
+ logger .info (f"Export in progress... Retrying in { retry_wait_time } seconds." )
222
+ time .sleep (retry_wait_time )
223
+ except Exception as e :
224
+ logger .exception (f"Error checking export status: { e } " )
225
+ time .sleep (retry_wait_time )
226
+ else :
227
+ logger .error ("Export process did not complete within the maximum retries." )
228
+ return None
229
+
230
+ # Step 3: Download the dataset
231
+ download_url = f"{ self .api_url } /api/tasks/{ task_id } /annotations?format=Segmentation+mask+1.1&location=local&save_images=false&action=download"
193
232
tmp_folder = tempfile .TemporaryDirectory ().name
194
233
os .makedirs (tmp_folder , exist_ok = True )
195
234
196
235
tmp_zip = tempfile .NamedTemporaryFile (suffix = ".zip" ).name
197
236
retry_count = 0
198
237
for retry in range (max_retry_count ):
199
238
try :
239
+ logger .info (f"Downloading exported dataset from: { download_url } " )
200
240
r = requests .get (download_url , allow_redirects = True , auth = self .auth )
201
- time .sleep (retry_wait_time )
202
241
203
242
with open (tmp_zip , "wb" ) as fp :
204
243
fp .write (r .content )
@@ -227,7 +266,7 @@ def download_from_cvat(self, max_retry_count=5, retry_wait_time=10):
227
266
Image .open (label ).save (dest )
228
267
logger .info (f"Copy Final Label: { label } to { dest } " )
229
268
230
- # Rename after consuming/downloading the labels
269
+ # Rename task after consuming/downloading the labels
231
270
patch_url = f"{ self .api_url } /api/tasks/{ task_id } "
232
271
body = {"name" : f"{ self .done_prefix } _{ task_name } " }
233
272
requests .patch (patch_url , allow_redirects = True , auth = self .auth , json = body )
0 commit comments