11from pathlib import Path
2+ import time
23from urllib .parse import urlparse
3- import boto3
4+
45from nucleus import DatasetItem , BoxPrediction
56
67PRESIGN_EXPIRY_SECONDS = 60 * 60 * 24 * 2 # 2 days
78
89TEST_MODEL_NAME = "[PyTest] Test Model"
9- TEST_MODEL_REFERENCE = "[PyTest] Test Model Reference"
1010TEST_MODEL_RUN = "[PyTest] Test Model Run"
1111TEST_DATASET_NAME = "[PyTest] Test Dataset"
1212TEST_SLICE_NAME = "[PyTest] Test Slice"
1313
14- TEST_MODEL_NAME = "[PyTest] Test Model Name"
15- TEST_MODEL_REFERENCE = "[PyTest] Test Model Reference"
16- TEST_MODEL_RUN = "[PyTest] Test Model Run Reference"
17- TEST_DATASET_NAME = "[PyTest] Test Dataset"
18- TEST_SLICE_NAME = "[PyTest] Test Slice"
14+
1915TEST_IMG_URLS = [
20- "s3 ://scaleapi-cust-lidar/Hesai/raw_data/2019-5-11/hesai_data_1557540003/undistorted/front_camera/1557540143.650423lf .jpg" ,
21- "s3 ://scaleapi-cust-lidar/Hesai/raw_data/2019-5-11/hesai_data_1557540003/undistorted/back_camera/1557540143.600352lf .jpg" ,
22- "s3 ://scaleapi-cust-lidar/Hesai/raw_data/2019-5-11/hesai_data_1557540003/undistorted/right_camera/1557540143.681730lf .jpg" ,
23- "s3 ://scaleapi-cust-lidar/Hesai/raw_data/2019-5-11/hesai_data_1557540003/undistorted/front_left_camera/1557540143.639619lf .jpg" ,
24- "s3 ://scaleapi-cust-lidar/Hesai/raw_data/2019-5-11/hesai_data_1557540003/undistorted/front_right_camera/1557540143.661212lf .jpg" ,
16+ "http ://farm1.staticflickr.com/107/309278012_7a1f67deaa_z .jpg" ,
17+ "http ://farm9.staticflickr.com/8001/7679588594_4e51b76472_z .jpg" ,
18+ "http ://farm6.staticflickr.com/5295/5465771966_76f9773af1_z .jpg" ,
19+ "http ://farm4.staticflickr.com/3449/4002348519_8ddfa4f2fb_z .jpg" ,
20+ "http ://farm1.staticflickr.com/6/7617223_d84fcbce0e_z .jpg" ,
2521]
22+
2623TEST_DATASET_ITEMS = [
2724 DatasetItem (TEST_IMG_URLS [0 ], "1" ),
2825 DatasetItem (TEST_IMG_URLS [1 ], "2" ),
3936]
4037
4138
42- def get_signed_url (url ):
43- bucket , key = get_s3_details (url )
44- return s3_sign (bucket , key )
45-
46-
47- def get_s3_details (url ):
48- # Expects S3 URL format to be https://<BUCKET>.s3.amazonaws.com/<KEY>
49- parsed = urlparse (url )
50- bucket = parsed .netloc [: parsed .netloc .find ("." )]
51- return bucket , parsed .path [1 :]
52-
53-
54- def s3_sign (bucket , key ):
55- s3 = boto3 .client ("s3" )
56- return s3 .generate_presigned_url (
57- ClientMethod = "get_object" ,
58- Params = {
59- "Bucket" : bucket ,
60- "Key" : key ,
61- },
62- ExpiresIn = PRESIGN_EXPIRY_SECONDS ,
63- )
64-
65-
6639def reference_id_from_url (url ):
6740 return Path (url ).name
6841
@@ -96,20 +69,21 @@ def reference_id_from_url(url):
9669 for i in range (len (TEST_IMG_URLS ))
9770]
9871
99- TEST_MASK_URL = "https://scale-ml.s3.amazonaws.com/home/nucleus/mscoco_masks_uint8/000000000285.png"
72+
73+ TEST_MASK_URL = "https://raw.githubusercontent.com/scaleapi/nucleus-python-client/master/tests/testdata/000000000285.png"
74+
10075TEST_SEGMENTATION_ANNOTATIONS = [
10176 {
10277 "reference_id" : reference_id_from_url (TEST_IMG_URLS [i ]),
10378 "annotation_id" : f"[Pytest] Segmentation Annotation Id{ i } " ,
104- "mask_url" : get_signed_url ( TEST_MASK_URL ) ,
79+ "mask_url" : TEST_MASK_URL ,
10580 "annotations" : [
10681 {"label" : "bear" , "index" : 2 },
10782 {"label" : "grass-merged" , "index" : 1 },
10883 ],
10984 }
11085 for i in range (len (TEST_IMG_URLS ))
11186]
112-
11387TEST_SEGMENTATION_PREDICTIONS = TEST_SEGMENTATION_ANNOTATIONS
11488
11589TEST_BOX_PREDICTIONS = [
@@ -122,7 +96,8 @@ def reference_id_from_url(url):
12296 for i in range (len (TEST_POLYGON_ANNOTATIONS ))
12397]
12498
125- TEST_INDEX_EMBEDDINGS_FILE = "https://scale-ml.s3.amazonaws.com/home/nucleus/pytest/pytest_embeddings_payload.json"
99+ TEST_INDEX_EMBEDDINGS_FILE = "https://raw.githubusercontent.com/scaleapi/nucleus-python-client/master/tests/testdata/pytest_embeddings_payload.json"
100+
126101
127102# Asserts that a box annotation instance matches a dict representing its properties.
128103# Useful to check annotation uploads/updates match.
@@ -184,4 +159,4 @@ def assert_polygon_prediction_matches_dict(
184159 assert_polygon_annotation_matches_dict (
185160 prediction_instance , prediction_dict
186161 )
187- assert prediction_instance .confidence == prediction_dict ["confidence" ]
162+ assert prediction_instance .confidence == prediction_dict ["confidence" ]
0 commit comments