Skip to content

Commit 12a7d0a

Browse files
authored
add support to fetch scene from an item (#370)
1 parent 1cc5213 commit 12a7d0a

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ All notable changes to the [Nucleus Python Client](https://github.com/scaleapi/n
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.14.26](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.14.26) - 2022-11-01
9+
10+
### Added
11+
- Support for fetching scene from a `DatasetItem.reference_id`
12+
Example:
13+
```python
14+
dataset = client.get_dataset("<dataset_id>")
15+
assert dataset.is_scene # only works on scene datasets
16+
some_item = dataset.iloc(0)
17+
dataset.get_scene_from_item_ref_id(some_item['item'].reference_id)
18+
```
19+
20+
821
## [0.14.25](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.14.25) - 2022-10-20
922

1023
### Updated

nucleus/dataset.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def __init__(self, dataset_id, client, name=None):
116116
self._client = client
117117
# NOTE: Optionally set name on creation such that the property access doesn't need to hit the server
118118
self._name = name
119+
self._is_scene = None
119120

120121
def __repr__(self):
121122
if os.environ.get("NUCLEUS_DEBUG", None):
@@ -141,10 +142,13 @@ def name(self) -> str:
141142
@property
142143
def is_scene(self) -> bool:
143144
"""Whether or not the dataset contains scenes exclusively."""
145+
if self._is_scene is not None:
146+
return self._is_scene
144147
response = self._client.make_request(
145148
{}, f"dataset/{self.id}/is_scene", requests.get
146149
)[DATASET_IS_SCENE_KEY]
147-
return response
150+
self._is_scene = response
151+
return self._is_scene
148152

149153
@property
150154
def model_runs(self) -> List[str]:
@@ -1375,6 +1379,25 @@ def get_scene(self, reference_id: str) -> Scene:
13751379
return VideoScene.from_json(response)
13761380
return LidarScene.from_json(response)
13771381

1382+
def get_scene_from_item_ref_id(
1383+
self, item_reference_id: str
1384+
) -> Optional[Scene]:
1385+
"""Given a dataset item reference ID, find the Scene it belongs to."""
1386+
if not self.is_scene:
1387+
print(
1388+
f"Dataset {self.id} is not a scene. Cannot call this endpoint."
1389+
)
1390+
return None
1391+
1392+
response = self._client.make_request(
1393+
payload=None,
1394+
route=f"dataset/{self.id}/scene/{item_reference_id}?from_item=1",
1395+
requests_command=requests.get,
1396+
)
1397+
if FRAME_RATE_KEY in response or VIDEO_URL_KEY in response:
1398+
return VideoScene.from_json(response)
1399+
return LidarScene.from_json(response)
1400+
13781401
def export_predictions(self, model):
13791402
"""Fetches all predictions of a model that were uploaded to the dataset.
13801403

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ exclude = '''
2121

2222
[tool.poetry]
2323
name = "scale-nucleus"
24-
version = "0.14.25"
24+
version = "0.14.26"
2525
description = "The official Python client library for Nucleus, the Data Platform for AI"
2626
license = "MIT"
2727
authors = ["Scale AI Nucleus Team <nucleusapi@scaleapi.com>"]

0 commit comments

Comments
 (0)