Skip to content

Commit 40f4dbc

Browse files
authored
[SDK-35] Improve mea tests (#1243)
2 parents ec24457 + 8c3f1b3 commit 40f4dbc

File tree

5 files changed

+96
-32
lines changed

5 files changed

+96
-32
lines changed

labelbox/schema/data_row_metadata.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ def _parse_ontology(raw_ontology) -> List[DataRowMetadataSchema]:
255255
options = []
256256
for option in schema["options"]:
257257
option["uid"] = option["id"]
258+
258259
options.append(
259260
DataRowMetadataSchema(**{
260261
**option,

tests/integration/annotation_import/conftest.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ def configured_project(client, initial_dataset, ontology, rand_gen, image_url):
517517
project._wait_until_data_rows_are_processed(data_row_ids=data_row_ids,
518518
sleep_interval=3)
519519

520-
batch = project.create_batch(
520+
project.create_batch(
521521
rand_gen(str),
522522
data_row_ids, # sample of data row objects
523523
5 # priority between 1(Highest) - 5(lowest)
@@ -894,9 +894,9 @@ def segmentation_inference(prediction_id_mapping):
894894
segmentation = prediction_id_mapping['superpixel'].copy()
895895
segmentation.update({
896896
'mask': {
897-
# TODO: Use a real URI
898-
'instanceURI': "sampleuri",
899-
'colorRGB': [0, 0, 0]
897+
"instanceURI":
898+
"https://storage.googleapis.com/labelbox-datasets/image_sample_data/raster_seg.png",
899+
"colorRGB": (255, 255, 255)
900900
}
901901
})
902902
del segmentation['tool']
@@ -1006,7 +1006,6 @@ def model_run_predictions(polygon_inference, rectangle_inference,
10061006
return [polygon_inference, rectangle_inference, line_inference]
10071007

10081008

1009-
# also used for label imports
10101009
@pytest.fixture
10111010
def object_predictions(polygon_inference, rectangle_inference, line_inference,
10121011
entity_inference, segmentation_inference):
@@ -1016,6 +1015,17 @@ def object_predictions(polygon_inference, rectangle_inference, line_inference,
10161015
]
10171016

10181017

1018+
@pytest.fixture
1019+
def object_predictions_for_annotation_import(polygon_inference,
1020+
rectangle_inference,
1021+
line_inference,
1022+
segmentation_inference):
1023+
return [
1024+
polygon_inference, rectangle_inference, line_inference,
1025+
segmentation_inference
1026+
]
1027+
1028+
10191029
@pytest.fixture
10201030
def classification_predictions(checklist_inference, text_inference):
10211031
return [checklist_inference, text_inference]
@@ -1074,6 +1084,8 @@ def model_run_with_training_metadata(rand_gen, model):
10741084
def model_run_with_data_rows(client, configured_project, model_run_predictions,
10751085
model_run, wait_for_label_processing):
10761086
configured_project.enable_model_assisted_labeling()
1087+
use_data_row_ids = [p['dataRow']['id'] for p in model_run_predictions]
1088+
model_run.upsert_data_rows(use_data_row_ids)
10771089

10781090
upload_task = LabelImport.create_from_objects(
10791091
client, configured_project.uid, f"label-import-{uuid.uuid4()}",
@@ -1096,6 +1108,8 @@ def model_run_with_all_project_labels(client, configured_project,
10961108
model_run_predictions, model_run,
10971109
wait_for_label_processing):
10981110
configured_project.enable_model_assisted_labeling()
1111+
use_data_row_ids = [p['dataRow']['id'] for p in model_run_predictions]
1112+
model_run.upsert_data_rows(use_data_row_ids)
10991113

11001114
upload_task = LabelImport.create_from_objects(
11011115
client, configured_project.uid, f"label-import-{uuid.uuid4()}",

tests/integration/annotation_import/test_mea_prediction_import.py

Lines changed: 54 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,13 @@
1111
"""
1212

1313

14-
def test_create_from_url(model_run_with_data_rows,
15-
annotation_import_test_helpers):
16-
name = str(uuid.uuid4())
17-
url = "https://storage.googleapis.com/labelbox-public-bucket/predictions_test_v2.ndjson"
18-
annotation_import = model_run_with_data_rows.add_predictions(
19-
name=name, predictions=url)
20-
assert annotation_import.model_run_id == model_run_with_data_rows.uid
21-
annotation_import_test_helpers.check_running_state(annotation_import, name,
22-
url)
23-
annotation_import.wait_until_done()
24-
25-
26-
def test_create_from_objects(model_run_with_data_rows, object_predictions,
14+
def test_create_from_objects(model_run_with_data_rows,
15+
object_predictions_for_annotation_import,
2716
annotation_import_test_helpers):
2817
name = str(uuid.uuid4())
18+
object_predictions = object_predictions_for_annotation_import
19+
use_data_row_ids = [p['dataRow']['id'] for p in object_predictions]
20+
model_run_with_data_rows.upsert_data_rows(use_data_row_ids)
2921

3022
annotation_import = model_run_with_data_rows.add_predictions(
3123
name=name, predictions=object_predictions)
@@ -36,15 +28,19 @@ def test_create_from_objects(model_run_with_data_rows, object_predictions,
3628
annotation_import.input_file_url, object_predictions)
3729
annotation_import.wait_until_done()
3830

31+
assert annotation_import.state == AnnotationImportState.FINISHED
32+
annotation_import_test_helpers.download_and_assert_status(
33+
annotation_import.status_file_url)
34+
3935

4036
def test_create_from_objects_global_key(client, model_run_with_data_rows,
41-
entity_inference,
37+
polygon_inference,
4238
annotation_import_test_helpers):
4339
name = str(uuid.uuid4())
44-
dr = client.get_data_row(entity_inference['dataRow']['id'])
45-
del entity_inference['dataRow']['id']
46-
entity_inference['dataRow']['globalKey'] = dr.global_key
47-
object_predictions = [entity_inference]
40+
dr = client.get_data_row(polygon_inference['dataRow']['id'])
41+
del polygon_inference['dataRow']['id']
42+
polygon_inference['dataRow']['globalKey'] = dr.global_key
43+
object_predictions = [polygon_inference]
4844

4945
annotation_import = model_run_with_data_rows.add_predictions(
5046
name=name, predictions=object_predictions)
@@ -55,6 +51,10 @@ def test_create_from_objects_global_key(client, model_run_with_data_rows,
5551
annotation_import.input_file_url, object_predictions)
5652
annotation_import.wait_until_done()
5753

54+
assert annotation_import.state == AnnotationImportState.FINISHED
55+
annotation_import_test_helpers.download_and_assert_status(
56+
annotation_import.status_file_url)
57+
5858

5959
def test_create_from_objects_with_confidence(predictions_with_confidence,
6060
model_run_with_data_rows,
@@ -77,15 +77,20 @@ def test_create_from_objects_with_confidence(predictions_with_confidence,
7777
annotation_import_test_helpers.assert_file_content(
7878
annotation_import.input_file_url, predictions_with_confidence)
7979
annotation_import.wait_until_done()
80+
8081
assert annotation_import.state == AnnotationImportState.FINISHED
8182
annotation_import_test_helpers.download_and_assert_status(
8283
annotation_import.status_file_url)
8384

8485

8586
def test_create_from_objects_all_project_labels(
86-
model_run_with_all_project_labels, object_predictions,
87+
model_run_with_all_project_labels,
88+
object_predictions_for_annotation_import,
8789
annotation_import_test_helpers):
8890
name = str(uuid.uuid4())
91+
object_predictions = object_predictions_for_annotation_import
92+
use_data_row_ids = [p['dataRow']['id'] for p in object_predictions]
93+
model_run_with_all_project_labels.upsert_data_rows(use_data_row_ids)
8994

9095
annotation_import = model_run_with_all_project_labels.add_predictions(
9196
name=name, predictions=object_predictions)
@@ -96,13 +101,18 @@ def test_create_from_objects_all_project_labels(
96101
annotation_import.input_file_url, object_predictions)
97102
annotation_import.wait_until_done()
98103

104+
assert annotation_import.state == AnnotationImportState.FINISHED
105+
annotation_import_test_helpers.download_and_assert_status(
106+
annotation_import.status_file_url)
107+
99108

100109
def test_model_run_project_labels(model_run_with_all_project_labels,
101110
model_run_predictions):
102111
model_run = model_run_with_all_project_labels
103112
# TODO: Move to export_v2
104113
model_run_exported_labels = model_run.export_labels(download=True)
105114
labels_indexed_by_schema_id = {}
115+
106116
for label in model_run_exported_labels:
107117
# assuming exported array of label 'objects' has only one label per data row... as usually is when there are no label revisions
108118
schema_id = label['Label']['objects'][0]['schemaId']
@@ -121,11 +131,17 @@ def test_model_run_project_labels(model_run_with_all_project_labels,
121131
assert actual_label['DataRow ID'] == expected_label['dataRow']['id']
122132

123133

124-
def test_create_from_label_objects(model_run_with_data_rows, object_predictions,
134+
def test_create_from_label_objects(model_run_with_data_rows,
135+
object_predictions_for_annotation_import,
125136
annotation_import_test_helpers):
126137
name = str(uuid.uuid4())
138+
use_data_row_ids = [
139+
p['dataRow']['id'] for p in object_predictions_for_annotation_import
140+
]
141+
model_run_with_data_rows.upsert_data_rows(use_data_row_ids)
127142

128-
predictions = list(NDJsonConverter.deserialize(object_predictions))
143+
predictions = list(
144+
NDJsonConverter.deserialize(object_predictions_for_annotation_import))
129145

130146
annotation_import = model_run_with_data_rows.add_predictions(
131147
name=name, predictions=predictions)
@@ -137,25 +153,39 @@ def test_create_from_label_objects(model_run_with_data_rows, object_predictions,
137153
annotation_import.input_file_url, normalized_predictions)
138154
annotation_import.wait_until_done()
139155

156+
assert annotation_import.state == AnnotationImportState.FINISHED
157+
annotation_import_test_helpers.download_and_assert_status(
158+
annotation_import.status_file_url)
159+
140160

141161
def test_create_from_local_file(tmp_path, model_run_with_data_rows,
142-
object_predictions,
162+
object_predictions_for_annotation_import,
143163
annotation_import_test_helpers):
164+
use_data_row_ids = [
165+
p['dataRow']['id'] for p in object_predictions_for_annotation_import
166+
]
167+
model_run_with_data_rows.upsert_data_rows(use_data_row_ids)
168+
144169
name = str(uuid.uuid4())
145170
file_name = f"{name}.ndjson"
146171
file_path = tmp_path / file_name
147172
with file_path.open("w") as f:
148-
parser.dump(object_predictions, f)
173+
parser.dump(object_predictions_for_annotation_import, f)
149174

150175
annotation_import = model_run_with_data_rows.add_predictions(
151176
name=name, predictions=str(file_path))
152177

153178
assert annotation_import.model_run_id == model_run_with_data_rows.uid
154179
annotation_import_test_helpers.check_running_state(annotation_import, name)
155180
annotation_import_test_helpers.assert_file_content(
156-
annotation_import.input_file_url, object_predictions)
181+
annotation_import.input_file_url,
182+
object_predictions_for_annotation_import)
157183
annotation_import.wait_until_done()
158184

185+
assert annotation_import.state == AnnotationImportState.FINISHED
186+
annotation_import_test_helpers.download_and_assert_status(
187+
annotation_import.status_file_url)
188+
159189

160190
def test_get(client, model_run_with_data_rows, annotation_import_test_helpers):
161191
name = str(uuid.uuid4())

tests/integration/conftest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from support.integration_client import Environ, IntegrationClient, EphemeralClient, AdminClient
2626

2727
IMG_URL = "https://picsum.photos/200/300.jpg"
28+
MASKABLE_IMG_URL = "https://storage.googleapis.com/labelbox-datasets/image_sample_data/2560px-Kitano_Street_Kobe01s5s4110.jpeg"
2829
SMALL_DATASET_URL = "https://storage.googleapis.com/lb-artifacts-testing-public/sdk_integration_test/potato.jpeg"
2930
DATA_ROW_PROCESSING_WAIT_TIMEOUT_SECONDS = 30
3031
DATA_ROW_PROCESSING_WAIT_SLEEP_INTERNAL_SECONDS = 3
@@ -108,7 +109,7 @@ def client(environ: str):
108109

109110
@pytest.fixture(scope="session")
110111
def image_url(client):
111-
return client.upload_data(requests.get(IMG_URL).content,
112+
return client.upload_data(requests.get(MASKABLE_IMG_URL).content,
112113
content_type="image/jpeg",
113114
filename="image.jpeg",
114115
sign=True)

tests/integration/export_v2/test_export_video.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,34 @@
11
import time
2+
3+
import pytest
24
import labelbox as lb
35
from labelbox.data.annotation_types.data.video import VideoData
46
import labelbox.types as lb_types
57
from labelbox.schema.annotation_import import AnnotationImportState
68

79

10+
@pytest.fixture
11+
def user_id(client):
12+
return client.get_user().uid
13+
14+
15+
@pytest.fixture
16+
def org_id(client):
17+
return client.get_organization().uid
18+
19+
820
def test_export_v2_video(client, configured_project_without_data_rows,
9-
video_data, video_data_row,
10-
bbox_video_annotation_objects, rand_gen):
21+
video_data, video_data_row, is_adv_enabled,
22+
bbox_video_annotation_objects, rand_gen, user_id,
23+
org_id):
24+
25+
orgid = client.get_organization().uid
26+
userid = client.get_user().uid
1127

1228
project = configured_project_without_data_rows
1329
project_id = project.uid
1430
labels = []
31+
1532
_, data_row_uids = video_data
1633
project.create_batch(
1734
rand_gen(str),
@@ -156,6 +173,7 @@ def test_export_v2_video(client, configured_project_without_data_rows,
156173
) #note we create 1 label per data row, 1 data row so 1 label
157174
export_label = project_export_labels[0]
158175
assert (export_label['label_kind']) == 'Video'
176+
159177
assert (export_label['label_details'].keys()
160178
) == expected_export_label['label_details'].keys()
161179

0 commit comments

Comments
 (0)