Skip to content

Commit b554529

Browse files
committed
adjust refloc payload format
1 parent f2cb018 commit b554529

File tree

3 files changed

+42
-11
lines changed

3 files changed

+42
-11
lines changed

nucleus/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
VERTICES_KEY = "vertices"
4949
BOX_TYPE = "box"
5050
POLYGON_TYPE = "polygon"
51+
SEGMENTATION_TYPE = "segmentation"
5152
GEOMETRY_KEY = "geometry"
5253
AUTOTAGS_KEY = "autotags"
5354
MASK_URL_KEY = "mask_url"

nucleus/dataset.py

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
from typing import List, Dict, Any, Optional, Union
22
from .dataset_item import DatasetItem
3-
from .annotation import BoxAnnotation, PolygonAnnotation
3+
from .annotation import (
4+
BoxAnnotation,
5+
PolygonAnnotation,
6+
SegmentationAnnotation,
7+
)
48
from .constants import (
59
DATASET_NAME_KEY,
610
DATASET_MODEL_RUNS_KEY,
@@ -12,9 +16,13 @@
1216
ITEM_KEY,
1317
DEFAULT_ANNOTATION_UPDATE_MODE,
1418
ANNOTATIONS_KEY,
19+
BOX_TYPE,
20+
POLYGON_TYPE,
21+
SEGMENTATION_TYPE,
1522
)
1623
from .payload_constructor import construct_model_run_creation_payload
1724

25+
1826
class Dataset:
1927
"""
2028
Nucleus Dataset. You can append images with metadata to your dataset,
@@ -170,6 +178,7 @@ def refloc(self, reference_id: str) -> dict:
170178
}
171179
"""
172180
response = self._client.dataitem_ref_id(self.id, reference_id)
181+
print("RESPONSE" + str(response))
173182
return self._format_dataset_item_response(response)
174183

175184
def loc(self, dataset_item_id: str) -> dict:
@@ -227,17 +236,34 @@ def list_autotags(self):
227236

228237
def _format_dataset_item_response(self, response: dict) -> dict:
229238
item = response.get(ITEM_KEY, None)
230-
annotation_payload = response.get(ANNOTATIONS_KEY, [])
239+
annotation_payload = response.get(ANNOTATIONS_KEY, {})
231240
if not item or not annotation_payload:
232241
# An error occured
233242
return response
234-
annotations = [
235-
BoxAnnotation.from_json(ann)
236-
if ann["type"] == "box"
237-
else PolygonAnnotation.from_json(ann)
238-
for ann in annotation_payload
239-
]
243+
244+
annotation_response = {}
245+
if BOX_TYPE in annotation_payload:
246+
annotation_response[BOX_TYPE] = [
247+
BoxAnnotation.from_json(ann)
248+
for ann in annotation_payload[BOX_TYPE]
249+
]
250+
if POLYGON_TYPE in annotation_payload:
251+
annotation_response[POLYGON_TYPE] = [
252+
PolygonAnnotation.from_json(ann)
253+
for ann in annotation_payload[POLYGON_TYPE]
254+
]
255+
if SEGMENTATION_TYPE in annotation_payload:
256+
annotation_response[SEGMENTATION_TYPE] = [
257+
SegmentationAnnotation.from_json(ann)
258+
for ann in annotation_payload[SEGMENTATION_TYPE]
259+
]
260+
# annotations = [
261+
# BoxAnnotation.from_json(ann)
262+
# if ann["type"] == "box"
263+
# else PolygonAnnotation.from_json(ann)
264+
# for ann in annotation_payload
265+
# ]
240266
return {
241267
ITEM_KEY: DatasetItem.from_json(item),
242-
ANNOTATIONS_KEY: annotations,
268+
ANNOTATIONS_KEY: annotation_response,
243269
}

nucleus/model.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
from typing import List, Optional, Dict, Union
22
from .dataset import Dataset
3-
from .prediction import BoxPrediction, PolygonPrediction
3+
from .prediction import (
4+
BoxPrediction,
5+
PolygonPrediction,
6+
SegmentationPrediction,
7+
)
48
from .model_run import ModelRun
59
from .constants import (
610
NAME_KEY,
@@ -25,7 +29,7 @@ def __init__(
2529
self._client = client
2630

2731
def __repr__(self):
28-
return f'Model(model_id={self.id}, name={self.name}, reference_id={self.reference_id}, metadata={self.metadata}, client={self._client})'
32+
return f"Model(model_id={self.id}, name={self.name}, reference_id={self.reference_id}, metadata={self.metadata}, client={self._client})"
2933

3034
def __eq__(self, other):
3135
return self.id == other.id

0 commit comments

Comments
 (0)