1212
1313FLAGS = flags .FLAGS
1414
15+ IMAGE_URL = "https://github.com/scaleapi/nucleus-python-client/raw/master/tests/testdata/airplane.jpeg"
16+
1517# Global flags
1618flags .DEFINE_string (
1719 "api_key" ,
2224# Dataset upload flags
2325flags .DEFINE_enum (
2426 "create_or_reuse_dataset" ,
25- "reuse " ,
27+ "create " ,
2628 ["create" , "reuse" ],
2729 "If create, upload a new dataset. If reuse, use the dataset id flag to reuse an existing dataset." ,
2830)
3840 lower_bound = 0 ,
3941)
4042flags .DEFINE_bool (
41- "cleanup_dataset" , False , "Whether to delete the dataset after the test."
43+ "cleanup_dataset" , True , "Whether to delete the dataset after the test."
4244)
4345
4446# Annotation upload flags
5254# Prediction upload flags
5355flags .DEFINE_integer (
5456 "num_predictions_per_dataset_item" ,
55- 1 ,
57+ 0 ,
5658 "Number of annotations per dataset item" ,
57- lower_bound = 1 ,
59+ lower_bound = 0 ,
5860)
5961
6062
@@ -73,7 +75,7 @@ def generate_fake_metadata(index):
7375def dataset_item_generator ():
7476 for i in range (FLAGS .num_dataset_items ):
7577 yield nucleus .DatasetItem (
76- image_location = f"https://fake_url_that_wont_be_read_since_its_privacy_mode/ { i } " ,
78+ image_location = IMAGE_URL ,
7779 reference_id = str (i ),
7880 metadata = generate_fake_metadata (i ),
7981 upload_to_scale = False ,
@@ -143,7 +145,7 @@ def upload_annotations(dataset: Dataset):
143145 print ("Starting annotation upload" )
144146 tic = time .time ()
145147 job = dataset .annotate (
146- list (annotation_generator ()), update = True , asynchronous = True
148+ list (annotation_generator ()), update = False , asynchronous = True
147149 )
148150 try :
149151 job .sleep_until_complete (False )
@@ -154,17 +156,27 @@ def upload_annotations(dataset: Dataset):
154156
155157
156158def upload_predictions (dataset : Dataset ):
157- print ("Starting Prediction upload" )
159+ model = client ().add_model (
160+ name = "Load test model" , reference_id = "model_" + str (time .time ())
161+ )
162+ run = model .create_run (
163+ name = "Test model run" , dataset = dataset , predictions = []
164+ )
165+
158166 tic = time .time ()
159- job = dataset .predict (
167+
168+ print ("Starting prediction upload" )
169+
170+ job = run .predict (
160171 list (prediction_generator ()), update = True , asynchronous = True
161172 )
173+
162174 try :
163175 job .sleep_until_complete (False )
164176 except JobError :
165177 print (job .errors ())
166178 toc = time .time ()
167- print ("Finished prediciton upload: %s" % (toc - tic ))
179+ print ("Finished prediction upload: %s" % (toc - tic ))
168180
169181
170182def main (unused_argv ):
@@ -173,10 +185,12 @@ def main(unused_argv):
173185 upload_annotations (dataset )
174186 except Exception as e :
175187 print (e )
188+
176189 try :
177190 upload_predictions (dataset )
178191 except Exception as e :
179192 print (e )
193+
180194 if FLAGS .cleanup_dataset and FLAGS .create_or_reuse_dataset == "create" :
181195 client ().delete_dataset (dataset .id )
182196
0 commit comments