Skip to content

Commit ed0a796

Browse files
authored
Changes for new video schema (#239)
* Switch the dataset item type * Comment removal * fixes * remove video frame location * Fix partial equality issues for test * remote check * Changes for deploy * typo * Remove unused import
1 parent 8c5f079 commit ed0a796

File tree

8 files changed

+40
-69
lines changed

8 files changed

+40
-69
lines changed

CHANGELOG.md

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

7+
## [0.6.7](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.6.7) - 2021-03-08
8+
9+
### Added
10+
- `get_autotag_refinement_metrics`
11+
- Get model using `model_run_id`
12+
- Video API change to require `image_location` instead of `video_frame_location` in `DatasetItems`
713
## [0.6.6](https://github.com/scaleapi/nucleus-python-client/releases/tag/v0.6.6) - 2021-02-18
814

915
### Added

nucleus/constants.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,6 @@
102102
UPLOAD_TO_SCALE_KEY = "upload_to_scale"
103103
URL_KEY = "url"
104104
VERTICES_KEY = "vertices"
105-
VIDEO_FRAME_LOCATION_KEY = "video_frame_location"
106-
VIDEO_FRAME_URL_KEY = "video_frame_url"
107-
VIDEO_KEY = "video"
108105
VIDEO_UPLOAD_TYPE_KEY = "video_upload_type"
109106
WIDTH_KEY = "width"
110107
YAW_KEY = "yaw"

nucleus/dataset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ def _append_video_scenes(
641641
)
642642

643643
if asynchronous:
644-
# TODO check_all_scene_paths_remote(scenes)
644+
check_all_scene_paths_remote(scenes)
645645
request_id = serialize_and_write_to_presigned_url(
646646
scenes, self.id, self._client
647647
)

nucleus/dataset_item.py

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
TYPE_KEY,
2323
UPLOAD_TO_SCALE_KEY,
2424
URL_KEY,
25-
VIDEO_FRAME_URL_KEY,
2625
W_KEY,
2726
X_KEY,
2827
Y_KEY,
@@ -121,35 +120,26 @@ def to_payload(self) -> dict:
121120
class DatasetItemType(Enum):
122121
IMAGE = "image"
123122
POINTCLOUD = "pointcloud"
124-
VIDEO = "video"
125123

126124

127125
@dataclass # pylint: disable=R0902
128126
class DatasetItem: # pylint: disable=R0902
129-
"""A dataset item is an image, pointcloud or video frame that has associated metadata.
127+
"""A dataset item is an image or pointcloud that has associated metadata.
130128
131129
Note: for 3D data, please include a :class:`CameraParams` object under a key named
132130
"camera_params" within the metadata dictionary. This will allow for projecting
133131
3D annotations to any image within a scene.
134132
135133
Args:
136-
image_location (Optional[str]): Required if pointcloud_location and
137-
video_frame_location are not present: The location containing the image for
138-
the given row of data. This can be a local path, or a remote URL. Remote
139-
formats supported include any URL (``http://`` or ``https://``) or URIs for
140-
AWS S3, Azure, or GCS (i.e. ``s3://``, ``gcs://``).
141-
142-
pointcloud_location (Optional[str]): Required if image_location and
143-
video_frame_location are not present: The remote URL containing the
144-
pointcloud JSON. Remote formats supported include any URL (``http://``
145-
or ``https://``) or URIs for AWS S3, Azure, or GCS (i.e. ``s3://``,
146-
``gcs://``).
147-
148-
video_frame_location (Optional[str]): Required if image_location and
149-
pointcloud_location are not present: The remote URL containing the
150-
video frame image. Remote formats supported include any URL (``http://``
151-
or ``https://``) or URIs for AWS S3, Azure, or GCS (i.e. ``s3://``,
152-
``gcs://``).
134+
image_location (Optional[str]): Required if pointcloud_location is not present:
135+
The location containing the image for the given row of data. This can be a local
136+
path, or a remote URL. Remote formats supported include any URL (``http://`` or
137+
``https://``) or URIs for AWS S3, Azure, or GCS (i.e. ``s3://``, ``gcs://``).
138+
139+
pointcloud_location (Optional[str]): Required if image_location is not present:
140+
The remote URL containing the pointcloud JSON. Remote formats supported include
141+
any URL (``http://`` or ``https://``) or URIs for AWS S3, Azure, or GCS (i.e.
142+
``s3://``, ``gcs://``).
153143
154144
reference_id (Optional[str]): A user-specified identifier to reference the
155145
item.
@@ -212,33 +202,23 @@ class DatasetItem: # pylint: disable=R0902
212202
metadata: Optional[dict] = None
213203
pointcloud_location: Optional[str] = None
214204
upload_to_scale: Optional[bool] = True
215-
video_frame_location: Optional[str] = None
216205

217206
def __post_init__(self):
218207
assert self.reference_id != "DUMMY_VALUE", "reference_id is required."
219-
assert (
220-
bool(self.image_location)
221-
+ bool(self.pointcloud_location)
222-
+ bool(self.video_frame_location)
223-
== 1
224-
), "Must specify exactly one of the image_location, pointcloud_location, video_frame_location parameters"
225-
if (
226-
self.pointcloud_location or self.video_frame_location
227-
) and not self.upload_to_scale:
208+
assert bool(self.image_location) != bool(
209+
self.pointcloud_location
210+
), "Must specify exactly one of the image_location or pointcloud_location parameters"
211+
if (self.pointcloud_location) and not self.upload_to_scale:
228212
raise NotImplementedError(
229-
"Skipping upload to Scale is not currently implemented for pointclouds and videos."
213+
"Skipping upload to Scale is not currently implemented for pointclouds."
230214
)
231215
self.local = (
232216
is_local_path(self.image_location) if self.image_location else None
233217
)
234218
self.type = (
235219
DatasetItemType.IMAGE
236220
if self.image_location
237-
else (
238-
DatasetItemType.POINTCLOUD
239-
if self.pointcloud_location
240-
else DatasetItemType.VIDEO
241-
)
221+
else DatasetItemType.POINTCLOUD
242222
)
243223
camera_params = (
244224
self.metadata.get(CAMERA_PARAMS_KEY, None)
@@ -258,7 +238,6 @@ def from_json(cls, payload: dict):
258238
return cls(
259239
image_location=image_url,
260240
pointcloud_location=payload.get(POINTCLOUD_URL_KEY, None),
261-
video_frame_location=payload.get(VIDEO_FRAME_URL_KEY, None),
262241
reference_id=payload.get(REFERENCE_ID_KEY, None),
263242
metadata=payload.get(METADATA_KEY, {}),
264243
upload_to_scale=payload.get(UPLOAD_TO_SCALE_KEY, True),
@@ -281,8 +260,6 @@ def to_payload(self, is_scene=False) -> dict:
281260
payload[URL_KEY] = self.image_location
282261
elif self.pointcloud_location:
283262
payload[URL_KEY] = self.pointcloud_location
284-
elif self.video_frame_location:
285-
payload[URL_KEY] = self.video_frame_location
286263
payload[TYPE_KEY] = self.type.value
287264
if self.camera_params:
288265
payload[CAMERA_PARAMS_KEY] = self.camera_params.to_payload()

nucleus/scene.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
NUM_SENSORS_KEY,
1414
POINTCLOUD_LOCATION_KEY,
1515
REFERENCE_ID_KEY,
16-
VIDEO_FRAME_LOCATION_KEY,
1716
VIDEO_UPLOAD_TYPE_KEY,
1817
)
1918

@@ -487,8 +486,11 @@ def validate(self):
487486
item, DatasetItem
488487
), "Each item in a scene must be a DatasetItem object"
489488
assert (
490-
item.video_frame_location is not None
491-
), "Each item in a scene must have a video_frame_location"
489+
item.image_location is not None
490+
), "Each item in a video scene must have an image_location"
491+
assert (
492+
item.upload_to_scale is not False
493+
), "Skipping upload to Scale is not currently implemented for videos"
492494

493495
def add_item(
494496
self, item: DatasetItem, index: int = None, update: bool = False
@@ -600,9 +602,3 @@ def check_all_scene_paths_remote(
600602
f"All paths for DatasetItems in a Scene must be remote, but {item.image_location} is either "
601603
"local, or a remote URL type that is not supported."
602604
)
603-
video_frame_location = getattr(item, VIDEO_FRAME_LOCATION_KEY)
604-
if video_frame_location and is_local_path(video_frame_location):
605-
raise ValueError(
606-
f"All paths for DatasetItems in a Scene must be remote, but {item.video_frame_location} is either "
607-
"local, or a remote URL type that is not supported."
608-
)

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.6.6"
24+
version = "0.6.7"
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>"]

tests/helpers.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@
9292
"frame_rate": 15,
9393
"frames": [
9494
{
95-
"video_frame_url": TEST_IMG_URLS[0],
96-
"type": "video",
95+
"image_url": TEST_IMG_URLS[0],
96+
"type": "image",
9797
"reference_id": "video_frame_0",
9898
"metadata": {"time": 123, "foo": "bar"},
9999
},
100100
{
101-
"video_frame_url": TEST_IMG_URLS[1],
102-
"type": "video",
101+
"image_url": TEST_IMG_URLS[1],
102+
"type": "image",
103103
"reference_id": "video_frame_1",
104104
"metadata": {"time": 124, "foo": "bar_2"},
105105
},
@@ -124,28 +124,25 @@ def reference_id_from_url(url):
124124

125125
TEST_VIDEO_ITEMS = [
126126
DatasetItem(
127-
None,
127+
TEST_IMG_URLS[0],
128128
reference_id_from_url(TEST_IMG_URLS[0]),
129129
None,
130130
None,
131131
True,
132-
TEST_IMG_URLS[0],
133132
),
134133
DatasetItem(
135-
None,
134+
TEST_IMG_URLS[1],
136135
reference_id_from_url(TEST_IMG_URLS[1]),
137136
None,
138137
None,
139138
True,
140-
TEST_IMG_URLS[1],
141139
),
142140
DatasetItem(
143-
None,
141+
TEST_IMG_URLS[2],
144142
reference_id_from_url(TEST_IMG_URLS[2]),
145143
None,
146144
None,
147145
True,
148-
TEST_IMG_URLS[2],
149146
),
150147
]
151148

tests/test_scene.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
TYPE_KEY,
2727
UPDATE_KEY,
2828
URL_KEY,
29-
VIDEO_KEY,
3029
VIDEO_UPLOAD_TYPE_KEY,
3130
)
3231
from nucleus.scene import flatten
@@ -307,15 +306,15 @@ def test_video_scene_add_item():
307306
FRAME_RATE_KEY: frame_rate,
308307
FRAMES_KEY: [
309308
{
310-
URL_KEY: TEST_VIDEO_ITEMS[2].video_frame_location,
309+
URL_KEY: TEST_VIDEO_ITEMS[2].image_location,
311310
REFERENCE_ID_KEY: TEST_VIDEO_ITEMS[2].reference_id,
312-
TYPE_KEY: VIDEO_KEY,
311+
TYPE_KEY: IMAGE_KEY,
313312
METADATA_KEY: TEST_VIDEO_ITEMS[2].metadata or {},
314313
},
315314
{
316-
URL_KEY: TEST_VIDEO_ITEMS[1].video_frame_location,
315+
URL_KEY: TEST_VIDEO_ITEMS[1].image_location,
317316
REFERENCE_ID_KEY: TEST_VIDEO_ITEMS[1].reference_id,
318-
TYPE_KEY: VIDEO_KEY,
317+
TYPE_KEY: IMAGE_KEY,
319318
METADATA_KEY: TEST_VIDEO_ITEMS[1].metadata or {},
320319
},
321320
],
@@ -572,7 +571,6 @@ def test_video_scene_upload_async(dataset_scene):
572571
VideoScene.from_json(scene_json) for scene_json in payload[SCENES_KEY]
573572
]
574573
update = payload[UPDATE_KEY]
575-
576574
job = dataset_scene.append(scenes, update=update, asynchronous=True)
577575
job.sleep_until_complete()
578576
status = job.status()

0 commit comments

Comments
 (0)