2
2
from urllib .parse import urlparse
3
3
import boto3
4
4
5
- PRESIGN_EXPIRY_SECONDS = 60 * 60 * 24 * 2 # 2 days
5
+ PRESIGN_EXPIRY_SECONDS = 60 * 60 * 24 * 2 # 2 days
6
6
7
- TEST_MODEL_NAME = ' [PyTest] Test Model'
8
- TEST_MODEL_REFERENCE = ' [PyTest] Test Model Reference'
9
- TEST_MODEL_RUN = ' [PyTest] Test Model Run'
10
- TEST_DATASET_NAME = ' [PyTest] Test Dataset'
11
- TEST_SLICE_NAME = ' [PyTest] Test Slice'
7
+ TEST_MODEL_NAME = " [PyTest] Test Model"
8
+ TEST_MODEL_REFERENCE = " [PyTest] Test Model Reference"
9
+ TEST_MODEL_RUN = " [PyTest] Test Model Run"
10
+ TEST_DATASET_NAME = " [PyTest] Test Dataset"
11
+ TEST_SLICE_NAME = " [PyTest] Test Slice"
12
12
TEST_IMG_URLS = [
13
- ' s3://scaleapi-attachments/BDD/BDD/bdd100k/images/100k/train/6dd63871-831611a6.jpg' ,
14
- ' s3://scaleapi-attachments/BDD/BDD/bdd100k/images/100k/train/82c1005c-e2d1d94f.jpg' ,
15
- ' s3://scaleapi-attachments/BDD/BDD/bdd100k/images/100k/train/7f2e1814-6591087d.jpg' ,
16
- ' s3://scaleapi-attachments/BDD/BDD/bdd100k/images/100k/train/06924f46-1708b96f.jpg' ,
17
- ' s3://scaleapi-attachments/BDD/BDD/bdd100k/images/100k/train/89b42832-10d662f4.jpg' ,
13
+ " s3://scaleapi-attachments/BDD/BDD/bdd100k/images/100k/train/6dd63871-831611a6.jpg" ,
14
+ " s3://scaleapi-attachments/BDD/BDD/bdd100k/images/100k/train/82c1005c-e2d1d94f.jpg" ,
15
+ " s3://scaleapi-attachments/BDD/BDD/bdd100k/images/100k/train/7f2e1814-6591087d.jpg" ,
16
+ " s3://scaleapi-attachments/BDD/BDD/bdd100k/images/100k/train/06924f46-1708b96f.jpg" ,
17
+ " s3://scaleapi-attachments/BDD/BDD/bdd100k/images/100k/train/89b42832-10d662f4.jpg" ,
18
18
]
19
19
20
+
20
21
def get_signed_url (url ):
21
22
bucket , key = get_s3_details (url )
22
23
return s3_sign (bucket , key )
23
24
25
+
24
26
def get_s3_details (url ):
25
27
# Expects S3 URL format to be https://<BUCKET>.s3.amazonaws.com/<KEY>
26
28
parsed = urlparse (url )
27
- bucket = parsed .netloc [:parsed .netloc .find ("." )]
29
+ bucket = parsed .netloc [: parsed .netloc .find ("." )]
28
30
return bucket , parsed .path [1 :]
29
31
32
+
30
33
def s3_sign (bucket , key ):
31
34
s3 = boto3 .client ("s3" )
32
35
return s3 .generate_presigned_url (
@@ -37,35 +40,37 @@ def s3_sign(bucket, key):
37
40
},
38
41
ExpiresIn = PRESIGN_EXPIRY_SECONDS ,
39
42
)
40
-
43
+
44
+
41
45
def reference_id_from_url (url ):
42
46
return Path (url ).name
43
47
48
+
44
49
TEST_BOX_ANNOTATIONS = [
45
50
{
46
- ' label' : f' [Pytest] Box Annotation ${ i } ' ,
47
- 'x' : 50 + i * 10 ,
48
- 'y' : 60 + i * 10 ,
49
- ' width' : 70 + i * 10 ,
50
- ' height' : 80 + i * 10 ,
51
- ' reference_id' : reference_id_from_url (TEST_IMG_URLS [i ]),
52
- ' annotation_id' : f' [Pytest] Box Annotation Annotation Id{ i } ' ,
51
+ " label" : f" [Pytest] Box Annotation ${ i } " ,
52
+ "x" : 50 + i * 10 ,
53
+ "y" : 60 + i * 10 ,
54
+ " width" : 70 + i * 10 ,
55
+ " height" : 80 + i * 10 ,
56
+ " reference_id" : reference_id_from_url (TEST_IMG_URLS [i ]),
57
+ " annotation_id" : f" [Pytest] Box Annotation Annotation Id{ i } " ,
53
58
}
54
59
for i in range (len (TEST_IMG_URLS ))
55
60
]
56
61
57
62
TEST_POLYGON_ANNOTATIONS = [
58
63
{
59
- ' label' : f' [Pytest] Polygon Annotation ${ i } ' ,
60
- ' vertices' : [
64
+ " label" : f" [Pytest] Polygon Annotation ${ i } " ,
65
+ " vertices" : [
61
66
{
62
- 'x' : 50 + i * 10 + j ,
63
- 'y' : 60 + i * 10 + j ,
67
+ "x" : 50 + i * 10 + j ,
68
+ "y" : 60 + i * 10 + j ,
64
69
}
65
70
for j in range (3 )
66
71
],
67
- ' reference_id' : reference_id_from_url (TEST_IMG_URLS [i ]),
68
- ' annotation_id' : f' [Pytest] Polygon Annotation Annotation Id{ i } ' ,
72
+ " reference_id" : reference_id_from_url (TEST_IMG_URLS [i ]),
73
+ " annotation_id" : f" [Pytest] Polygon Annotation Annotation Id{ i } " ,
69
74
}
70
75
for i in range (len (TEST_IMG_URLS ))
71
76
]
@@ -76,52 +81,62 @@ def reference_id_from_url(url):
76
81
"reference_id" : reference_id_from_url (TEST_IMG_URLS [i ]),
77
82
"mask_url" : get_signed_url (TEST_MASK_URL ),
78
83
"annotations" : [
79
- {"label" : "bear" , "index" : 2 }, {"label" : "grass-merged" , "index" : 1 }
80
- ]
84
+ {"label" : "bear" , "index" : 2 },
85
+ {"label" : "grass-merged" , "index" : 1 },
86
+ ],
81
87
}
82
88
for i in range (len (TEST_IMG_URLS ))
83
89
]
84
90
85
91
TEST_BOX_PREDICTIONS = [
86
- {
87
- ** TEST_BOX_ANNOTATIONS [i ],
88
- 'confidence' : 0.10 * i
89
- }
92
+ {** TEST_BOX_ANNOTATIONS [i ], "confidence" : 0.10 * i }
90
93
for i in range (len (TEST_BOX_ANNOTATIONS ))
91
94
]
92
95
93
96
TEST_POLYGON_PREDICTIONS = [
94
- {
95
- ** TEST_POLYGON_ANNOTATIONS [i ],
96
- 'confidence' : 0.10 * i
97
- }
97
+ {** TEST_POLYGON_ANNOTATIONS [i ], "confidence" : 0.10 * i }
98
98
for i in range (len (TEST_POLYGON_ANNOTATIONS ))
99
99
]
100
100
101
101
102
102
# Asserts that a box annotation instance matches a dict representing its properties.
103
103
# Useful to check annotation uploads/updates match.
104
104
def assert_box_annotation_matches_dict (annotation_instance , annotation_dict ):
105
- assert annotation_instance .label == annotation_dict ['label' ]
106
- assert annotation_instance .x == annotation_dict ['x' ]
107
- assert annotation_instance .y == annotation_dict ['y' ]
108
- assert annotation_instance .height == annotation_dict ['height' ]
109
- assert annotation_instance .width == annotation_dict ['width' ]
110
- assert annotation_instance .annotation_id == annotation_dict ['annotation_id' ]
111
-
112
- def assert_polygon_annotation_matches_dict (annotation_instance , annotation_dict ):
113
- assert annotation_instance .label == annotation_dict ['label' ]
114
- assert annotation_instance .annotation_id == annotation_dict ['annotation_id' ]
115
- for instance_pt , dict_pt in zip (annotation_instance .vertices , annotation_dict ['vertices' ]):
116
- assert instance_pt ['x' ] == dict_pt ['x' ]
117
- assert instance_pt ['y' ] == dict_pt ['y' ]
105
+ assert annotation_instance .label == annotation_dict ["label" ]
106
+ assert annotation_instance .x == annotation_dict ["x" ]
107
+ assert annotation_instance .y == annotation_dict ["y" ]
108
+ assert annotation_instance .height == annotation_dict ["height" ]
109
+ assert annotation_instance .width == annotation_dict ["width" ]
110
+ assert (
111
+ annotation_instance .annotation_id == annotation_dict ["annotation_id" ]
112
+ )
113
+
114
+
115
+ def assert_polygon_annotation_matches_dict (
116
+ annotation_instance , annotation_dict
117
+ ):
118
+ assert annotation_instance .label == annotation_dict ["label" ]
119
+ assert (
120
+ annotation_instance .annotation_id == annotation_dict ["annotation_id" ]
121
+ )
122
+ for instance_pt , dict_pt in zip (
123
+ annotation_instance .vertices , annotation_dict ["vertices" ]
124
+ ):
125
+ assert instance_pt ["x" ] == dict_pt ["x" ]
126
+ assert instance_pt ["y" ] == dict_pt ["y" ]
127
+
118
128
119
129
# Asserts that a box prediction instance matches a dict representing its properties.
120
130
# Useful to check prediction uploads/updates match.
121
131
def assert_box_prediction_matches_dict (prediction_instance , prediction_dict ):
122
132
assert_box_annotation_matches_dict (prediction_instance , prediction_dict )
123
- assert prediction_instance .confidence == prediction_dict [' confidence' ]
133
+ assert prediction_instance .confidence == prediction_dict [" confidence" ]
124
134
125
- def assert_polygon_prediction_matches_dict (prediction_instance , prediction_dict ):
126
- assert_polygon_annotation_matches_dict (prediction_instance , prediction_dict )
127
- assert prediction_instance .confidence == prediction_dict ['confidence' ]
135
+
136
+ def assert_polygon_prediction_matches_dict (
137
+ prediction_instance , prediction_dict
138
+ ):
139
+ assert_polygon_annotation_matches_dict (
140
+ prediction_instance , prediction_dict
141
+ )
142
+ assert prediction_instance .confidence == prediction_dict ["confidence" ]
0 commit comments