Skip to content

Commit 5b501d1

Browse files
author
Ubuntu
committed
relevant tests pass
1 parent ab05d1f commit 5b501d1

File tree

4 files changed

+66
-35
lines changed

4 files changed

+66
-35
lines changed

conftest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ def dataset(CLIENT):
2828
CLIENT.delete_dataset(ds.id)
2929

3030

31+
@pytest.fixture()
32+
def model(CLIENT):
33+
model = CLIENT.create_model(TEST_DATASET_NAME, "fake_reference_id")
34+
yield model
35+
CLIENT.delete_model(model.id)
36+
37+
3138
if __name__ == "__main__":
3239
client = nucleus.NucleusClient(API_KEY)
3340
# ds = client.create_dataset("Test Dataset With Autotags")

nucleus/annotation_uploader.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,20 @@ def accumulate_dict_values(dicts: Iterable[dict]):
2424
result = {}
2525
for d in dicts:
2626
for key, value in d.items():
27-
if key not in result or key == "dataset_id":
27+
if (
28+
key not in result
29+
or key == "dataset_id"
30+
or key == "model_run_id"
31+
):
2832
result[key] = value
2933
else:
3034
result[key] += value
3135
return result
3236

3337

3438
class AnnotationUploader:
35-
"""This is a helper class not intended for direct use. Please use dataset.annotate.
39+
"""This is a helper class not intended for direct use. Please use dataset.annotate
40+
or dataset.upload_predictions.
3641
3742
This class is purely a helper class for implementing dataset.annotate/dataset.predict.
3843
"""

tests/test_prediction.py

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -194,39 +194,6 @@ def test_non_existent_taxonomy_category_gt_upload(model_run):
194194
)
195195

196196

197-
def test_segmentation_pred_upload(model_run):
198-
prediction = SegmentationPrediction.from_json(
199-
TEST_SEGMENTATION_PREDICTIONS[0]
200-
)
201-
response = model_run.predict(annotations=[prediction])
202-
203-
assert response["model_run_id"] == model_run.model_run_id
204-
assert response["predictions_processed"] == 1
205-
assert response["predictions_ignored"] == 0
206-
207-
response = model_run.refloc(prediction.reference_id)["segmentation"]
208-
assert isinstance(response[0], SegmentationPrediction)
209-
210-
assert_segmentation_annotation_matches_dict(
211-
response[0], TEST_SEGMENTATION_PREDICTIONS[0]
212-
)
213-
214-
215-
def test_segmentation_pred_upload_ignore(model_run):
216-
prediction = SegmentationPrediction.from_json(
217-
TEST_SEGMENTATION_PREDICTIONS[0]
218-
)
219-
response1 = model_run.predict(annotations=[prediction])
220-
221-
assert response1["predictions_processed"] == 1
222-
223-
# Upload Duplicate annotation
224-
response = model_run.predict(annotations=[prediction])
225-
assert response["model_run_id"] == model_run.model_run_id
226-
assert response["predictions_processed"] == 0
227-
assert response["predictions_ignored"] == 1
228-
229-
230197
def test_box_pred_upload_update(model_run):
231198
prediction = BoxPrediction(**TEST_BOX_PREDICTIONS[0])
232199
response = model_run.predict(annotations=[prediction])

tests/test_segmentation.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,65 @@
11
from nucleus.annotation import SegmentationAnnotation
22
from nucleus.dataset import Dataset
3+
from nucleus.model import Model
4+
from nucleus.prediction import SegmentationPrediction
35
from tests.helpers import (
46
NUM_VALID_SEGMENTATIONS_IN_MAIN_DATASET,
57
TEST_LOCAL_MASK_URL,
68
TEST_SEGMENTATION_ANNOTATIONS,
9+
TEST_SEGMENTATION_PREDICTIONS,
710
assert_segmentation_annotation_matches_dict,
811
)
912

1013

14+
def test_segmentation_pred_upload_local(dataset: Dataset, model: Model):
15+
prediction = SegmentationPrediction.from_json(
16+
TEST_SEGMENTATION_PREDICTIONS[0]
17+
)
18+
prediction.mask_url = TEST_LOCAL_MASK_URL
19+
response = dataset.upload_predictions(model, [prediction])
20+
21+
assert response["predictions_processed"] == 1
22+
23+
response = dataset.predictions_refloc(model, prediction.reference_id)[
24+
"segmentation"
25+
][0]
26+
assert isinstance(response, SegmentationPrediction)
27+
assert response == prediction
28+
29+
30+
def test_segmentation_pred_upload(dataset: Dataset, model: Model):
31+
prediction = SegmentationPrediction.from_json(
32+
TEST_SEGMENTATION_PREDICTIONS[0]
33+
)
34+
response = dataset.upload_predictions(model, [prediction])
35+
36+
assert response["predictions_processed"] == 1
37+
assert response["predictions_ignored"] == 0
38+
39+
response = dataset.predictions_refloc(model, prediction.reference_id)[
40+
"segmentation"
41+
]
42+
assert isinstance(response[0], SegmentationPrediction)
43+
44+
assert_segmentation_annotation_matches_dict(
45+
response[0], TEST_SEGMENTATION_PREDICTIONS[0]
46+
)
47+
48+
49+
def test_segmentation_pred_upload_ignore(dataset: Dataset, model: Model):
50+
prediction = SegmentationPrediction.from_json(
51+
TEST_SEGMENTATION_PREDICTIONS[0]
52+
)
53+
response1 = dataset.upload_predictions(model, [prediction])
54+
55+
assert response1["predictions_processed"] == 1
56+
57+
# Upload Duplicate annotation
58+
response = dataset.upload_predictions(model, [prediction])
59+
assert response["predictions_processed"] == 0
60+
assert response["predictions_ignored"] == 1
61+
62+
1163
def test_single_local_semseg_gt_upload(dataset: Dataset):
1264
request_annotation = SegmentationAnnotation.from_json(
1365
TEST_SEGMENTATION_ANNOTATIONS[0]

0 commit comments

Comments
 (0)