Skip to content

Commit

Permalink
Limit the sizes of some of the nightly examples (#4545)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
emilk authored Dec 15, 2023
1 parent 899f72b commit 32a468c
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 21 deletions.
1 change: 1 addition & 0 deletions examples/python/nuscenes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ description: "Visualize the nuScenes dataset including lidar, radar, images, and
thumbnail: https://static.rerun.io/nuscenes/64a50a9d67cbb69ae872551989ee807b195f6b5d/480w.png
thumbnail_dimensions: [480, 282]
channel: nightly
build_args: ["--seconds=5"]
---

<picture>
Expand Down
43 changes: 29 additions & 14 deletions examples/python/nuscenes/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def ensure_scene_available(root_dir: pathlib.Path, dataset_version: str, scene_n
raise ValueError(f"{scene_name=} not found in dataset")


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

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

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

log_lidar_and_ego_pose(first_lidar_token, nusc, max_timestamp_us)
log_cameras(first_camera_tokens, nusc, max_timestamp_us)
log_radars(first_radar_tokens, nusc, max_timestamp_us)
log_annotations(first_sample_token, nusc, max_timestamp_us)

def log_lidar_and_ego_pose(first_lidar_token: str, nusc: nuscenes.NuScenes) -> None:

def log_lidar_and_ego_pose(first_lidar_token: str, nusc: nuscenes.NuScenes, max_timestamp_us: float) -> None:
"""Log lidar data and vehicle pose."""
current_lidar_token = first_lidar_token

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

if max_timestamp_us < sample_data["timestamp"]:
break

# timestamps are in microseconds
rr.set_time_seconds("timestamp", sample_data["timestamp"] * 1e-6)

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


def log_cameras(first_camera_tokens: list[str], nusc: nuscenes.NuScenes) -> None:
def log_cameras(first_camera_tokens: list[str], nusc: nuscenes.NuScenes, max_timestamp_us: float) -> None:
"""Log camera data."""
for first_camera_token in first_camera_tokens:
current_camera_token = first_camera_token
while current_camera_token != "":
sample_data = nusc.get("sample_data", current_camera_token)
if max_timestamp_us < sample_data["timestamp"]:
break
sensor_name = sample_data["channel"]
rr.set_time_seconds("timestamp", sample_data["timestamp"] * 1e-6)
data_file_path = nusc.dataroot / sample_data["filename"]
rr.log(f"world/ego_vehicle/{sensor_name}", rr.ImageEncoded(path=data_file_path))
current_camera_token = sample_data["next"]


def log_radars(first_radar_tokens: list[str], nusc: nuscenes.NuScenes) -> None:
def log_radars(first_radar_tokens: list[str], nusc: nuscenes.NuScenes, max_timestamp_us: float) -> None:
"""Log radar data."""
for first_radar_token in first_radar_tokens:
current_camera_token = first_radar_token
while current_camera_token != "":
sample_data = nusc.get("sample_data", current_camera_token)
if max_timestamp_us < sample_data["timestamp"]:
break
sensor_name = sample_data["channel"]
rr.set_time_seconds("timestamp", sample_data["timestamp"] * 1e-6)
data_file_path = nusc.dataroot / sample_data["filename"]
Expand All @@ -139,14 +149,16 @@ def log_radars(first_radar_tokens: list[str], nusc: nuscenes.NuScenes) -> None:
current_camera_token = sample_data["next"]


def log_annotations(first_sample_token: str, nusc: nuscenes.NuScenes) -> None:
def log_annotations(first_sample_token: str, nusc: nuscenes.NuScenes, max_timestamp_us: float) -> None:
"""Log 3D bounding boxes."""
label2id: dict[str, int] = {}
current_sample_token = first_sample_token
while current_sample_token != "":
sample = nusc.get("sample", current_sample_token)
rr.set_time_seconds("timestamp", sample["timestamp"] * 1e-6)
ann_tokens = sample["anns"]
sample_data = nusc.get("sample", current_sample_token)
if max_timestamp_us < sample_data["timestamp"]:
break
rr.set_time_seconds("timestamp", sample_data["timestamp"] * 1e-6)
ann_tokens = sample_data["anns"]
sizes = []
centers = []
rotations = []
Expand All @@ -164,7 +176,7 @@ def log_annotations(first_sample_token: str, nusc: nuscenes.NuScenes) -> None:
class_ids.append(label2id[ann["category_name"]])

rr.log("world/anns", rr.Boxes3D(sizes=sizes, centers=centers, rotations=rotations, class_ids=class_ids))
current_sample_token = sample["next"]
current_sample_token = sample_data["next"]

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

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

rr.script_setup(args, "rerun_example_nuscenes")
log_nuscenes(args.root_dir, args.dataset_version, args.scene_name)
log_nuscenes(args.root_dir, args.dataset_version, args.scene_name, max_time_sec=args.seconds)

rr.script_teardown(args)

Expand Down
1 change: 1 addition & 0 deletions examples/python/objectron/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ tags: [2D, 3D, object-detection, pinhole-camera]
thumbnail: https://static.rerun.io/objectron/8ea3a37e6b4af2e06f8e2ea5e70c1951af67fea8/480w.png
thumbnail_dimensions: [480, 268]
channel: nightly
build_args: ["--frames=150"]
---

<picture>
Expand Down
1 change: 1 addition & 0 deletions examples/python/open_photogrammetry_format/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ tags: [2d, 3d, camera, photogrammetry]
thumbnail: https://static.rerun.io/open_photogrammetry_format/603d5605f9670889bc8bce3365f16b831fce1eb1/480w.png
thumbnail_dimensions: [480, 310]
channel: nightly
build_args: ["--jpeg-quality=50"]
---

<picture>
Expand Down
22 changes: 17 additions & 5 deletions examples/python/open_photogrammetry_format/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import requests
import rerun as rr
import tqdm
from PIL import Image
from pyopf.io import load
from pyopf.resolve import resolve

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

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

def log_calibrated_cameras(self) -> None:
def log_calibrated_cameras(self, jpeg_quality: int | None) -> None:
"""
Log the project's calibrated cameras as individual frames.
Expand Down Expand Up @@ -180,7 +181,12 @@ def log_calibrated_cameras(self) -> None:
camera_xyz=rr.ViewCoordinates.RUB,
),
)
rr.log(entity + "/image/rgb", rr.ImageEncoded(path=self.path.parent / camera.uri))

if jpeg_quality is not None:
with Image.open(self.path.parent / camera.uri) as img:
rr.log(entity + "/image/rgb", rr.Image(np.array(img)).compress(jpeg_quality=jpeg_quality))
else:
rr.log(entity + "/image/rgb", rr.ImageEncoded(path=self.path.parent / camera.uri))


def main() -> None:
Expand All @@ -199,6 +205,12 @@ def main() -> None:
action="store_true",
help="Log all cameras globally instead of as individual frames in the timeline.",
)
parser.add_argument(
"--jpeg-quality",
type=int,
default=None,
help="If specified, compress the camera images with the given JPEG quality.",
)

rr.script_add_args(parser)

Expand All @@ -213,7 +225,7 @@ def main() -> None:
rr.script_setup(args, "rerun_example_open_photogrammetry_format")
rr.log("world", rr.ViewCoordinates.RIGHT_HAND_Z_UP, timeless=True)
project.log_point_cloud()
project.log_calibrated_cameras()
project.log_calibrated_cameras(jpeg_quality=args.jpeg_quality)
rr.script_teardown(args)


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
numpy
pillow
pyopf; python_version >= '3.10' # silence error if this requirements.txt gets pulled in a <3.10 venv
requests
rerun-sdk
Expand Down
1 change: 1 addition & 0 deletions examples/python/rgbd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ tags: [2D, 3D, depth, nyud, pinhole-camera]
thumbnail: https://static.rerun.io/rgbd/4109d29ed52fa0a8f980fcdd0e9673360c76879f/480w.png
thumbnail_dimensions: [480, 254]
channel: nightly
build_args: ["--frames=300"]
---

<picture>
Expand Down
16 changes: 14 additions & 2 deletions examples/python/rgbd/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import argparse
import os
import sys
import zipfile
from datetime import datetime
from pathlib import Path
Expand Down Expand Up @@ -50,7 +51,7 @@ def read_depth_image(buf: bytes) -> npt.NDArray[Any]:
return img


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

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

if len(files_with_timestamps) > frames:
files_with_timestamps = files_with_timestamps[:frames]

for time, f in files_with_timestamps:
rr.set_time_seconds("time", time.timestamp())

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


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

Expand All @@ -159,6 +166,11 @@ def download_progress(url: str, dst: Path) -> None:
log_nyud_data(
recording_path=recording_path,
subset_idx=args.subset_idx,
frames=args.frames,
)

rr.script_teardown(args)


if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions examples/rust/objectron/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ python: https://github.com/rerun-io/rerun/tree/latest/examples/python/objectron/
rust: https://github.com/rerun-io/rerun/tree/latest/examples/rust/objectron/src/main.rs
tags: [2D, 3D, object-detection, pinhole-camera]
thumbnail: https://static.rerun.io/objectron/8ea3a37e6b4af2e06f8e2ea5e70c1951af67fea8/480w.png
build_args: ["--frames=100"]
---

<picture>
Expand Down

0 comments on commit 32a468c

Please sign in to comment.