@ -8,6 +8,7 @@ import os
import requests
import requests
from io import BytesIO
from io import BytesIO
import mimetypes
import mimetypes
from time import sleep
from PIL import Image
from PIL import Image
@ -57,7 +58,9 @@ class CLI():
response = self . session . get ( url )
response = self . session . get ( url )
response . raise_for_status ( )
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
""" Create a new task with the given name and labels JSON and
add the files to it . """
add the files to it . """
url = self . api . tasks
url = self . api . tasks
@ -69,7 +72,26 @@ class CLI():
response . raise_for_status ( )
response . raise_for_status ( )
response_json = response . json ( )
response_json = response . json ( )
log . info ( ' Created task ID: {id} NAME: {name} ' . format ( * * 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 ) :
def tasks_delete ( self , task_ids , * * kwargs ) :
""" Delete a list of tasks, ignoring those which don ' t exist. """
""" Delete a list of tasks, ignoring those which don ' t exist. """
@ -135,8 +157,8 @@ class CLI():
while True :
while True :
response = self . session . put (
response = self . session . put (
url ,
url ,
files = { ' annotation_file ' : open ( filename , ' rb ' ) }
files = { ' annotation_file ' : open ( filename , ' rb ' ) }
)
)
response . raise_for_status ( )
response . raise_for_status ( )
if response . status_code == 201 :
if response . status_code == 201 :
break
break
@ -176,6 +198,9 @@ class CVAT_API_V1():
def tasks_id_frame_id ( self , task_id , frame_id , quality ) :
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 )
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 ) :
def tasks_id_annotations_format ( self , task_id , fileformat ) :
return self . tasks_id ( task_id ) + ' /annotations?format= {} ' \
return self . tasks_id ( task_id ) + ' /annotations?format= {} ' \
. format ( fileformat )
. format ( fileformat )