Skip to content

Commit 32a468c

Browse files
authored
Limit the sizes of some of the nightly examples (#4545)
They are still not exactlty _small_, but a lot _smaller_, and since they all stream, it should be pretty fine anyways ``` detect_and_track_objects.rrd (55.3 MiB) nuscenes.rrd (90.0 MiB) objectron.rrd (81.1 MiB) open_photogrammetry_format.rrd (67.6 MiB) raw_mesh.rrd (116 kiB) rgbd.rrd (36.8 MiB) segment_anything_model.rrd (8.5 MiB) ``` This helped in figuring out what to focus on: * #4542 ### Checklist * [x] I have read and agree to [Contributor Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and the [Code of Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md) * [x] I've included a screenshot or gif (if applicable) * [x] I have tested the web demo (if applicable): * Using newly built examples: [app.rerun.io](https://app.rerun.io/pr/4545/index.html) * Using examples from latest `main` build: [app.rerun.io](https://app.rerun.io/pr/4545/index.html?manifest_url=https://app.rerun.io/version/main/examples_manifest.json) * Using full set of examples from `nightly` build: [app.rerun.io](https://app.rerun.io/pr/4545/index.html?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json) * [x] The PR title and labels are set such as to maximize their usefulness for the next release's CHANGELOG - [PR Build Summary](https://build.rerun.io/pr/4545) - [Docs preview](https://rerun.io/preview/4aa4c24e403c16b455d8be8b02b98d5c8164fa53/docs) <!--DOCS-PREVIEW--> - [Examples preview](https://rerun.io/preview/4aa4c24e403c16b455d8be8b02b98d5c8164fa53/examples) <!--EXAMPLES-PREVIEW--> - [Recent benchmark results](https://build.rerun.io/graphs/crates.html) - [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)
1 parent 899f72b commit 32a468c

9 files changed

Lines changed: 66 additions & 21 deletions

File tree

examples/python/nuscenes/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ description: "Visualize the nuScenes dataset including lidar, radar, images, and
66
thumbnail: https://static.rerun.io/nuscenes/64a50a9d67cbb69ae872551989ee807b195f6b5d/480w.png
77
thumbnail_dimensions: [480, 282]
88
channel: nightly
9+
build_args: ["--seconds=5"]
910
---
1011

1112
<picture>

examples/python/nuscenes/main.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def ensure_scene_available(root_dir: pathlib.Path, dataset_version: str, scene_n
4747
raise ValueError(f"{scene_name=} not found in dataset")
4848

4949

50-
def log_nuscenes(root_dir: pathlib.Path, dataset_version: str, scene_name: str) -> None:
50+
def log_nuscenes(root_dir: pathlib.Path, dataset_version: str, scene_name: str, max_time_sec: float) -> None:
5151
"""Log nuScenes scene."""
5252
nusc = nuscenes.NuScenes(version=dataset_version, dataroot=root_dir, verbose=True)
5353

@@ -72,20 +72,26 @@ def log_nuscenes(root_dir: pathlib.Path, dataset_version: str, scene_name: str)
7272
elif sample_data["sensor_modality"] == "camera":
7373
first_camera_tokens.append(sample_data_token)
7474

75-
log_lidar_and_ego_pose(first_lidar_token, nusc)
76-
log_cameras(first_camera_tokens, nusc)
77-
log_radars(first_radar_tokens, nusc)
78-
log_annotations(first_sample_token, nusc)
75+
first_timestamp_us = nusc.get("sample_data", first_lidar_token)["timestamp"]
76+
max_timestamp_us = first_timestamp_us + 1e6 * max_time_sec
7977

78+
log_lidar_and_ego_pose(first_lidar_token, nusc, max_timestamp_us)
79+
log_cameras(first_camera_tokens, nusc, max_timestamp_us)
80+
log_radars(first_radar_tokens, nusc, max_timestamp_us)
81+
log_annotations(first_sample_token, nusc, max_timestamp_us)
8082

81-
def log_lidar_and_ego_pose(first_lidar_token: str, nusc: nuscenes.NuScenes) -> None:
83+
84+
def log_lidar_and_ego_pose(first_lidar_token: str, nusc: nuscenes.NuScenes, max_timestamp_us: float) -> None:
8285
"""Log lidar data and vehicle pose."""
8386
current_lidar_token = first_lidar_token
8487

8588
while current_lidar_token != "":
8689
sample_data = nusc.get("sample_data", current_lidar_token)
8790
sensor_name = sample_data["channel"]
8891

92+
if max_timestamp_us < sample_data["timestamp"]:
93+
break
94+
8995
# timestamps are in microseconds
9096
rr.set_time_seconds("timestamp", sample_data["timestamp"] * 1e-6)
9197

@@ -109,25 +115,29 @@ def log_lidar_and_ego_pose(first_lidar_token: str, nusc: nuscenes.NuScenes) -> N
109115
rr.log(f"world/ego_vehicle/{sensor_name}", rr.Points3D(points, colors=point_colors))
110116

111117

112-
def log_cameras(first_camera_tokens: list[str], nusc: nuscenes.NuScenes) -> None:
118+
def log_cameras(first_camera_tokens: list[str], nusc: nuscenes.NuScenes, max_timestamp_us: float) -> None:
113119
"""Log camera data."""
114120
for first_camera_token in first_camera_tokens:
115121
current_camera_token = first_camera_token
116122
while current_camera_token != "":
117123
sample_data = nusc.get("sample_data", current_camera_token)
124+
if max_timestamp_us < sample_data["timestamp"]:
125+
break
118126
sensor_name = sample_data["channel"]
119127
rr.set_time_seconds("timestamp", sample_data["timestamp"] * 1e-6)
120128
data_file_path = nusc.dataroot / sample_data["filename"]
121129
rr.log(f"world/ego_vehicle/{sensor_name}", rr.ImageEncoded(path=data_file_path))
122130
current_camera_token = sample_data["next"]
123131

124132

125-
def log_radars(first_radar_tokens: list[str], nusc: nuscenes.NuScenes) -> None:
133+
def log_radars(first_radar_tokens: list[str], nusc: nuscenes.NuScenes, max_timestamp_us: float) -> None:
126134
"""Log radar data."""
127135
for first_radar_token in first_radar_tokens:
128136
current_camera_token = first_radar_token
129137
while current_camera_token != "":
130138
sample_data = nusc.get("sample_data", current_camera_token)
139+
if max_timestamp_us < sample_data["timestamp"]:
140+
break
131141
sensor_name = sample_data["channel"]
132142
rr.set_time_seconds("timestamp", sample_data["timestamp"] * 1e-6)
133143
data_file_path = nusc.dataroot / sample_data["filename"]
@@ -139,14 +149,16 @@ def log_radars(first_radar_tokens: list[str], nusc: nuscenes.NuScenes) -> None:
139149
current_camera_token = sample_data["next"]
140150

141151

142-
def log_annotations(first_sample_token: str, nusc: nuscenes.NuScenes) -> None:
152+
def log_annotations(first_sample_token: str, nusc: nuscenes.NuScenes, max_timestamp_us: float) -> None:
143153
"""Log 3D bounding boxes."""
144154
label2id: dict[str, int] = {}
145155
current_sample_token = first_sample_token
146156
while current_sample_token != "":
147-
sample = nusc.get("sample", current_sample_token)
148-
rr.set_time_seconds("timestamp", sample["timestamp"] * 1e-6)
149-
ann_tokens = sample["anns"]
157+
sample_data = nusc.get("sample", current_sample_token)
158+
if max_timestamp_us < sample_data["timestamp"]:
159+
break
160+
rr.set_time_seconds("timestamp", sample_data["timestamp"] * 1e-6)
161+
ann_tokens = sample_data["anns"]
150162
sizes = []
151163
centers = []
152164
rotations = []
@@ -164,7 +176,7 @@ def log_annotations(first_sample_token: str, nusc: nuscenes.NuScenes) -> None:
164176
class_ids.append(label2id[ann["category_name"]])
165177

166178
rr.log("world/anns", rr.Boxes3D(sizes=sizes, centers=centers, rotations=rotations, class_ids=class_ids))
167-
current_sample_token = sample["next"]
179+
current_sample_token = sample_data["next"]
168180

169181
# skipping for now since labels take too much space in 3D view (see https://github.com/rerun-io/rerun/issues/4451)
170182
# annotation_context = [(i, label) for label, i in label2id.items()]
@@ -213,13 +225,16 @@ def main() -> None:
213225
help="Scene name to visualize (typically of form 'scene-xxxx')",
214226
)
215227
parser.add_argument("--dataset-version", type=str, default="v1.0-mini", help="Scene id to visualize")
228+
parser.add_argument(
229+
"--seconds", type=float, default=float("inf"), help="If specified, limits the number of seconds logged"
230+
)
216231
rr.script_add_args(parser)
217232
args = parser.parse_args()
218233

219234
ensure_scene_available(args.root_dir, args.dataset_version, args.scene_name)
220235

221236
rr.script_setup(args, "rerun_example_nuscenes")
222-
log_nuscenes(args.root_dir, args.dataset_version, args.scene_name)
237+
log_nuscenes(args.root_dir, args.dataset_version, args.scene_name, max_time_sec=args.seconds)
223238

224239
rr.script_teardown(args)
225240

examples/python/objectron/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ tags: [2D, 3D, object-detection, pinhole-camera]
66
thumbnail: https://static.rerun.io/objectron/8ea3a37e6b4af2e06f8e2ea5e70c1951af67fea8/480w.png
77
thumbnail_dimensions: [480, 268]
88
channel: nightly
9+
build_args: ["--frames=150"]
910
---
1011

1112
<picture>

examples/python/open_photogrammetry_format/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ tags: [2d, 3d, camera, photogrammetry]
55
thumbnail: https://static.rerun.io/open_photogrammetry_format/603d5605f9670889bc8bce3365f16b831fce1eb1/480w.png
66
thumbnail_dimensions: [480, 310]
77
channel: nightly
8+
build_args: ["--jpeg-quality=50"]
89
---
910

1011
<picture>

examples/python/open_photogrammetry_format/main.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import requests
2222
import rerun as rr
2323
import tqdm
24+
from PIL import Image
2425
from pyopf.io import load
2526
from pyopf.resolve import resolve
2627

@@ -109,10 +110,10 @@ def from_dataset(cls, dataset: str, log_as_frames: bool = True) -> OPFProject:
109110

110111
def log_point_cloud(self) -> None:
111112
"""Log the project's point cloud."""
112-
pcl = self.project.point_cloud_objs[0]
113-
rr.log("world/pcl", rr.Points3D(pcl.nodes[0].position, colors=pcl.nodes[0].color), timeless=True)
113+
points = self.project.point_cloud_objs[0].nodes[0]
114+
rr.log("world/points", rr.Points3D(points.position, colors=points.color), timeless=True)
114115

115-
def log_calibrated_cameras(self) -> None:
116+
def log_calibrated_cameras(self, jpeg_quality: int | None) -> None:
116117
"""
117118
Log the project's calibrated cameras as individual frames.
118119
@@ -180,7 +181,12 @@ def log_calibrated_cameras(self) -> None:
180181
camera_xyz=rr.ViewCoordinates.RUB,
181182
),
182183
)
183-
rr.log(entity + "/image/rgb", rr.ImageEncoded(path=self.path.parent / camera.uri))
184+
185+
if jpeg_quality is not None:
186+
with Image.open(self.path.parent / camera.uri) as img:
187+
rr.log(entity + "/image/rgb", rr.Image(np.array(img)).compress(jpeg_quality=jpeg_quality))
188+
else:
189+
rr.log(entity + "/image/rgb", rr.ImageEncoded(path=self.path.parent / camera.uri))
184190

185191

186192
def main() -> None:
@@ -199,6 +205,12 @@ def main() -> None:
199205
action="store_true",
200206
help="Log all cameras globally instead of as individual frames in the timeline.",
201207
)
208+
parser.add_argument(
209+
"--jpeg-quality",
210+
type=int,
211+
default=None,
212+
help="If specified, compress the camera images with the given JPEG quality.",
213+
)
202214

203215
rr.script_add_args(parser)
204216

@@ -213,7 +225,7 @@ def main() -> None:
213225
rr.script_setup(args, "rerun_example_open_photogrammetry_format")
214226
rr.log("world", rr.ViewCoordinates.RIGHT_HAND_Z_UP, timeless=True)
215227
project.log_point_cloud()
216-
project.log_calibrated_cameras()
228+
project.log_calibrated_cameras(jpeg_quality=args.jpeg_quality)
217229
rr.script_teardown(args)
218230

219231

examples/python/open_photogrammetry_format/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
numpy
2+
pillow
23
pyopf; python_version >= '3.10' # silence error if this requirements.txt gets pulled in a <3.10 venv
34
requests
45
rerun-sdk

examples/python/rgbd/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ tags: [2D, 3D, depth, nyud, pinhole-camera]
55
thumbnail: https://static.rerun.io/rgbd/4109d29ed52fa0a8f980fcdd0e9673360c76879f/480w.png
66
thumbnail_dimensions: [480, 254]
77
channel: nightly
8+
build_args: ["--frames=300"]
89
---
910

1011
<picture>

examples/python/rgbd/main.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import argparse
1010
import os
11+
import sys
1112
import zipfile
1213
from datetime import datetime
1314
from pathlib import Path
@@ -50,7 +51,7 @@ def read_depth_image(buf: bytes) -> npt.NDArray[Any]:
5051
return img
5152

5253

53-
def log_nyud_data(recording_path: Path, subset_idx: int = 0) -> None:
54+
def log_nyud_data(recording_path: Path, subset_idx: int, frames: int) -> None:
5455
rr.log("world", rr.ViewCoordinates.RIGHT_HAND_Y_DOWN, timeless=True)
5556

5657
with zipfile.ZipFile(recording_path, "r") as archive:
@@ -67,6 +68,9 @@ def log_nyud_data(recording_path: Path, subset_idx: int = 0) -> None:
6768
files_with_timestamps = [(parse_timestamp(f.filename), f) for f in subset]
6869
files_with_timestamps.sort(key=lambda t: t[0])
6970

71+
if len(files_with_timestamps) > frames:
72+
files_with_timestamps = files_with_timestamps[:frames]
73+
7074
for time, f in files_with_timestamps:
7175
rr.set_time_seconds("time", time.timestamp())
7276

@@ -140,7 +144,7 @@ def download_progress(url: str, dst: Path) -> None:
140144
bar.update(size)
141145

142146

143-
if __name__ == "__main__":
147+
def main() -> None:
144148
parser = argparse.ArgumentParser(description="Logs rich data using the Rerun SDK.")
145149
parser.add_argument(
146150
"--recording",
@@ -150,6 +154,9 @@ def download_progress(url: str, dst: Path) -> None:
150154
help="Name of the NYU Depth Dataset V2 recording",
151155
)
152156
parser.add_argument("--subset-idx", type=int, default=0, help="The index of the subset of the recording to use.")
157+
parser.add_argument(
158+
"--frames", type=int, default=sys.maxsize, help="If specified, limits the number of frames logged"
159+
)
153160
rr.script_add_args(parser)
154161
args = parser.parse_args()
155162

@@ -159,6 +166,11 @@ def download_progress(url: str, dst: Path) -> None:
159166
log_nyud_data(
160167
recording_path=recording_path,
161168
subset_idx=args.subset_idx,
169+
frames=args.frames,
162170
)
163171

164172
rr.script_teardown(args)
173+
174+
175+
if __name__ == "__main__":
176+
main()

examples/rust/objectron/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ python: https://github.com/rerun-io/rerun/tree/latest/examples/python/objectron/
44
rust: https://github.com/rerun-io/rerun/tree/latest/examples/rust/objectron/src/main.rs
55
tags: [2D, 3D, object-detection, pinhole-camera]
66
thumbnail: https://static.rerun.io/objectron/8ea3a37e6b4af2e06f8e2ea5e70c1951af67fea8/480w.png
7+
build_args: ["--frames=100"]
78
---
89

910
<picture>

0 commit comments

Comments
 (0)