3
3
import pandas as pd
4
4
from dotenv import load_dotenv
5
5
from diffgram import Project
6
+ import time
7
+
8
+ start_time = time .time ()
6
9
7
10
load_dotenv ()
8
11
15
18
host = os .getenv ('HOST' )
16
19
)
17
20
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
+
18
31
number_of_images = None
19
- while number_of_images is None :
32
+ while True :
20
33
try :
21
34
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 == '' :
23
36
number_of_images = len (image_list )
37
+ break
24
38
number_of_images = int (number_of_images_to_import )
39
+ break
25
40
except :
26
41
print ("Invalid input: please input positive number" )
27
42
28
- image_list = image_list [:int ( number_of_images_to_import ) ]
43
+ image_list = image_list [:number_of_images ]
29
44
30
45
new_schema_name = None
46
+ imported_label_traker = []
47
+ lables_objects = {}
31
48
while True :
32
49
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
36
63
break
37
64
except :
38
65
print ("Seems like schema with this name already exists" )
49
76
except :
50
77
print ("Seems like annotation file is not here" )
51
78
52
- imported_label_traker = []
53
- lables_objects = {}
54
-
55
79
succeslully_imported = []
56
80
import_errors = []
57
81
105
129
print (f'Error ocurred while importing { image } ' )
106
130
107
131
print (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