|
1 | 1 | from typing import List, Dict, Any, Optional, Union
|
2 | 2 | from .dataset_item import DatasetItem
|
3 |
| -from .annotation import BoxAnnotation, PolygonAnnotation |
| 3 | +from .annotation import ( |
| 4 | + BoxAnnotation, |
| 5 | + PolygonAnnotation, |
| 6 | + SegmentationAnnotation, |
| 7 | +) |
4 | 8 | from .constants import (
|
5 | 9 | DATASET_NAME_KEY,
|
6 | 10 | DATASET_MODEL_RUNS_KEY,
|
|
12 | 16 | ITEM_KEY,
|
13 | 17 | DEFAULT_ANNOTATION_UPDATE_MODE,
|
14 | 18 | ANNOTATIONS_KEY,
|
| 19 | + BOX_TYPE, |
| 20 | + POLYGON_TYPE, |
| 21 | + SEGMENTATION_TYPE, |
15 | 22 | )
|
16 | 23 | from .payload_constructor import construct_model_run_creation_payload
|
17 | 24 |
|
| 25 | + |
18 | 26 | class Dataset:
|
19 | 27 | """
|
20 | 28 | Nucleus Dataset. You can append images with metadata to your dataset,
|
@@ -170,6 +178,7 @@ def refloc(self, reference_id: str) -> dict:
|
170 | 178 | }
|
171 | 179 | """
|
172 | 180 | response = self._client.dataitem_ref_id(self.id, reference_id)
|
| 181 | + print("RESPONSE" + str(response)) |
173 | 182 | return self._format_dataset_item_response(response)
|
174 | 183 |
|
175 | 184 | def loc(self, dataset_item_id: str) -> dict:
|
@@ -227,17 +236,34 @@ def list_autotags(self):
|
227 | 236 |
|
228 | 237 | def _format_dataset_item_response(self, response: dict) -> dict:
|
229 | 238 | item = response.get(ITEM_KEY, None)
|
230 |
| - annotation_payload = response.get(ANNOTATIONS_KEY, []) |
| 239 | + annotation_payload = response.get(ANNOTATIONS_KEY, {}) |
231 | 240 | if not item or not annotation_payload:
|
232 | 241 | # An error occured
|
233 | 242 | 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 | + # ] |
240 | 266 | return {
|
241 | 267 | ITEM_KEY: DatasetItem.from_json(item),
|
242 |
| - ANNOTATIONS_KEY: annotations, |
| 268 | + ANNOTATIONS_KEY: annotation_response, |
243 | 269 | }
|
0 commit comments