Skip to content

Commit ad186d3

Browse files
author
Ubuntu
committed
Fix one more bug and remove use of annotate_segmentation endpoint
1 parent 01464a1 commit ad186d3

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

nucleus/annotation_uploader.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ 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:
27+
if key not in result or key == "dataset_id":
2828
result[key] = value
2929
else:
3030
result[key] += value
@@ -112,15 +112,12 @@ def make_batched_annotate_requests(
112112
"Segmentation batches" if segmentation else "Annotation batches"
113113
)
114114
for batch in self._client.tqdm_bar(batches, desc=progress_bar_name):
115-
if segmentation:
116-
payload = construct_segmentation_payload(batch, update)
117-
# TODO: remove validation checks in backend for /annotate
118-
# since it should work.
119-
route = f"dataset/{self.dataset_id}/annotate_segmentation"
120-
else:
121-
payload = construct_annotation_payload(batch, update)
122-
route = f"dataset/{self.dataset_id}/annotate"
123-
responses.append(self._client.make_request(payload, route))
115+
payload = construct_annotation_payload(batch, update)
116+
responses.append(
117+
self._client.make_request(
118+
payload, route=f"dataset/{self.dataset_id}/annotate"
119+
)
120+
)
124121
return responses
125122

126123
def make_batched_file_form_data_requests(

nucleus/payload_constructor.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Dict, List, Optional, Union
1+
from typing import Any, Dict, List, Optional, Union
22

33
from .annotation import (
44
BoxAnnotation,
@@ -72,11 +72,22 @@ def construct_annotation_payload(
7272
],
7373
update: bool,
7474
) -> dict:
75-
annotations = []
76-
for annotation_item in annotation_items:
77-
annotations.append(annotation_item.to_payload())
78-
79-
return {ANNOTATIONS_KEY: annotations, ANNOTATION_UPDATE_KEY: update}
75+
annotations = [
76+
annotation.to_payload()
77+
for annotation in annotation_items
78+
if not isinstance(annotation, SegmentationAnnotation)
79+
]
80+
segmentations = [
81+
annotation.to_payload()
82+
for annotation in annotation_items
83+
if isinstance(annotation, SegmentationAnnotation)
84+
]
85+
payload: Dict[str, Any] = {ANNOTATION_UPDATE_KEY: update}
86+
if annotations:
87+
payload[ANNOTATIONS_KEY] = annotations
88+
if segmentations:
89+
payload[SEGMENTATIONS_KEY] = segmentations
90+
return payload
8091

8192

8293
def construct_segmentation_payload(

0 commit comments

Comments
 (0)