33import pandas as pd
44from dotenv import load_dotenv
55from diffgram import Project
6+ import time
7+
8+ start_time = time .time ()
69
710load_dotenv ()
811
1518 host = os .getenv ('HOST' )
1619)
1720
21+ list = project .directory .get (name = "Default" ).list_files ()
22+
23+ for file in list :
24+ original_filename = file .__dict__ ['original_filename' ]
25+ initia_filename = original_filename .replace ('_' , ' (' ).replace ('.' , ').' )
26+ if initia_filename in image_list :
27+ image_list .remove (initia_filename )
28+
29+ shema_list = project .get_label_schema_list ()
30+
1831number_of_images = None
19- while number_of_images is None :
32+ while True :
2033 try :
2134 number_of_images_to_import = input ("How many images do you want to import? (blank to import all) " )
22- if not number_of_images_to_import :
35+ if number_of_images_to_import == '' :
2336 number_of_images = len (image_list )
37+ break
2438 number_of_images = int (number_of_images_to_import )
39+ break
2540 except :
2641 print ("Invalid input: please input positive number" )
2742
28- image_list = image_list [:int ( number_of_images_to_import ) ]
43+ image_list = image_list [:number_of_images ]
2944
3045new_schema_name = None
46+ imported_label_traker = []
47+ lables_objects = {}
3148while True :
3249 try :
33- new_schema_name = input ("Give a name for a new schema: " )
34- schema = project .new_schema (name = new_schema_name )
35- print ("Schema successfully created" )
50+ new_schema_name = input ("Shema name (if shema with this name already exists - it will be used, otherwise new shema will be created): " )
51+ shema_list = project .get_label_schema_list ()
52+ schema = [existing_schema for existing_schema in shema_list if existing_schema .get ('name' ) == new_schema_name ]
53+ if not schema :
54+ schema = project .new_schema (name = new_schema_name )
55+ print ("Schema successfully created" )
56+ else :
57+ schema = schema [0 ]
58+ schema_label_list = project .get_label_list (schema .get ('id' ))
59+ for label in schema_label_list :
60+ imported_label_traker .append (label ['label' ]['name' ])
61+ lables_objects [label ['label' ]['name' ]] = label
62+ pass
3663 break
3764 except :
3865 print ("Seems like schema with this name already exists" )
4976 except :
5077 print ("Seems like annotation file is not here" )
5178
52- imported_label_traker = []
53- lables_objects = {}
54-
5579succeslully_imported = []
5680import_errors = []
5781
105129 print (f'Error ocurred while importing { image } ' )
106130
107131print (f"Successfully imported { len (succeslully_imported )} file(s): " , succeslully_imported )
108- print (f"Errors while importing { len (succeslully_imported )} file(s): " , import_errors )
132+ print (f"Errors while importing { len (succeslully_imported )} file(s): " , import_errors )
133+
134+ print ("--- %s seconds ---" % (time .time () - start_time ))
0 commit comments