Skip to content

Commit 2d7b350

Browse files
authored
Allow image+annotation generator to give mirrored URLs (#433)
* Allow image+annotation generator to give mirrored URLs * add to docstring
1 parent 75ff078 commit 2d7b350

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

nucleus/dataset.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,11 +1447,13 @@ def items_and_annotations(
14471447
def items_and_annotation_generator(
14481448
self,
14491449
query: Optional[str] = None,
1450+
use_mirrored_images: bool = False,
14501451
) -> Iterable[Dict[str, Union[DatasetItem, Dict[str, List[Annotation]]]]]:
14511452
"""Provides a generator of all DatasetItems and Annotations in the dataset.
14521453
14531454
Args:
14541455
query: Structured query compatible with the `Nucleus query language <https://nucleus.scale.com/docs/query-language-reference>`_.
1456+
use_mirrored_images: If True, returns the location of the mirrored image hosted in Scale S3. Useful when the original image is no longer available.
14551457
14561458
Returns:
14571459
Generator where each element is a dict containing the DatasetItem
@@ -1477,6 +1479,7 @@ def items_and_annotation_generator(
14771479
result_key=EXPORT_FOR_TRAINING_KEY,
14781480
page_size=10000, # max ES page size
14791481
query=query,
1482+
chip=use_mirrored_images,
14801483
)
14811484
for data in json_generator:
14821485
for ia in convert_export_payload([data], has_predictions=False):

nucleus/dataset_item.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
METADATA_KEY,
1919
ORIGINAL_IMAGE_URL_KEY,
2020
POINTCLOUD_URL_KEY,
21+
PROCESSED_URL_KEY,
2122
REFERENCE_ID_KEY,
2223
TYPE_KEY,
2324
URL_KEY,
@@ -156,8 +157,10 @@ def __post_init__(self):
156157
@classmethod
157158
def from_json(cls, payload: dict):
158159
"""Instantiates dataset item object from schematized JSON dict payload."""
159-
image_url = payload.get(IMAGE_URL_KEY, None) or payload.get(
160-
ORIGINAL_IMAGE_URL_KEY, None
160+
image_url = (
161+
payload.get(PROCESSED_URL_KEY, None)
162+
or payload.get(IMAGE_URL_KEY, None)
163+
or payload.get(ORIGINAL_IMAGE_URL_KEY, None)
161164
)
162165
pointcloud_url = payload.get(POINTCLOUD_URL_KEY, None)
163166

0 commit comments

Comments
 (0)