Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up our examples #2424

Merged
merged 9 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions crates/re_components/src/tensor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1192,11 +1192,6 @@ impl DecodedTensor {
| TensorData::F64(_) => Ok(Self(maybe_encoded_tensor)),

TensorData::JPEG(jpeg_bytes) => {
re_log::debug!(
"Decoding JPEG image of shape {:?}",
maybe_encoded_tensor.shape()
);

let [h, w, c] = maybe_encoded_tensor
.image_height_width_channels()
.ok_or_else(|| {
Expand Down
5 changes: 5 additions & 0 deletions crates/re_space_view_text/src/scene_part.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ impl ScenePart<TextSpaceView> for SceneText {
}
}

{
re_tracing::profile_scope!("sort");
self.text_entries.sort_by_key(|entry| entry.time);
}

Vec::new()
}
}
2 changes: 1 addition & 1 deletion examples/python/arkitscenes/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def log_annotated_bboxes(annotation: dict[str, Any]) -> tuple[npt.NDArray[np.flo
# Generate a color per object that can be reused across both 3D obb and their 2D projections
# TODO(pablovela5620): Once #1581 or #1728 is resolved this can be removed
color_positions = np.linspace(0, 1, num_objects)
colormap = plt.cm.get_cmap("viridis")
colormap = plt.colormaps["viridis"]
colors = [colormap(pos) for pos in color_positions]

for i, label_info in enumerate(annotation["data"]):
Expand Down
10 changes: 5 additions & 5 deletions examples/python/mp_pose/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pathlib import Path
from typing import Any, Final, Iterator

import cv2 as cv
import cv2
import mediapipe as mp
import numpy as np
import numpy.typing as npt
Expand Down Expand Up @@ -42,7 +42,7 @@ def track_pose(video_path: str, segment: bool) -> None:

with closing(VideoSource(video_path)) as video_source, mp_pose.Pose(enable_segmentation=segment) as pose:
for bgr_frame in video_source.stream_bgr():
rgb = cv.cvtColor(bgr_frame.data, cv.COLOR_BGR2RGB)
rgb = cv2.cvtColor(bgr_frame.data, cv2.COLOR_BGR2RGB)
rr.set_time_seconds("time", bgr_frame.time)
rr.set_time_sequence("frame_idx", bgr_frame.idx)
rr.log_image("video/rgb", rgb)
Expand Down Expand Up @@ -91,7 +91,7 @@ class VideoFrame:

class VideoSource:
def __init__(self, path: str):
self.capture = cv.VideoCapture(path)
self.capture = cv2.VideoCapture(path)

if not self.capture.isOpened():
logging.error("Couldn't open video at %s", path)
Expand All @@ -101,9 +101,9 @@ def close(self) -> None:

def stream_bgr(self) -> Iterator[VideoFrame]:
while self.capture.isOpened():
idx = int(self.capture.get(cv.CAP_PROP_POS_FRAMES))
idx = int(self.capture.get(cv2.CAP_PROP_POS_FRAMES))
is_open, bgr = self.capture.read()
time_ms = self.capture.get(cv.CAP_PROP_POS_MSEC)
time_ms = self.capture.get(cv2.CAP_PROP_POS_MSEC)

if not is_open:
break
Expand Down
2 changes: 1 addition & 1 deletion examples/python/plots/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def log_bar_chart() -> None:
mean = 0
std = 1
variance = np.square(std)
x = np.arange(-5, 5, 0.01)
x = np.arange(-5, 5, 0.1)
y = np.exp(-np.square(x - mean) / 2 * variance) / (np.sqrt(2 * np.pi * variance))
rr.log_tensor("bar_chart", y)

Expand Down
2 changes: 1 addition & 1 deletion examples/python/stable_diffusion/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def get_downloaded_path(dataset_dir: Path, image_name: str) -> str:


def main() -> None:
parser = argparse.ArgumentParser(description="Logs Objectron data using the Rerun SDK.")
parser = argparse.ArgumentParser(description="Stable diffusion.")
parser.add_argument(
"--image",
type=str,
Expand Down
20 changes: 8 additions & 12 deletions examples/python/tracking_hf_opencv/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pathlib import Path
from typing import Any, Final, Sequence

import cv2 as cv
import cv2
import numpy as np
import numpy.typing as npt
import requests
Expand Down Expand Up @@ -84,7 +84,7 @@ def detect_objects_to_track(self, rgb: npt.NDArray[np.uint8], frame_idx: int) ->
inputs = self.feature_extractor(images=pil_im_small, return_tensors="pt")
_, _, scaled_height, scaled_width = inputs["pixel_values"].shape
scaled_size = (scaled_width, scaled_height)
rgb_scaled = cv.resize(rgb, scaled_size)
rgb_scaled = cv2.resize(rgb, scaled_size)
rr.log_image("image/scaled/rgb", rgb_scaled)
rr.log_disconnected_space("image/scaled") # Note: Haven't implemented 2D transforms yet.

Expand Down Expand Up @@ -161,7 +161,7 @@ def __init__(self, tracking_id: int, detection: Detection, bgr: npt.NDArray[np.u
self.tracked = detection.scaled_to_fit_image(bgr)
self.num_recent_undetected_frames = 0

self.tracker = cv.TrackerCSRT_create()
self.tracker = cv2.TrackerCSRT_create()
bbox_xywh_rounded = [int(val) for val in self.tracked.bbox_xywh]
self.tracker.init(bgr, bbox_xywh_rounded)
self.log_tracked()
Expand Down Expand Up @@ -201,7 +201,7 @@ def log_tracked(self) -> None:
def update_with_detection(self, detection: Detection, bgr: npt.NDArray[np.uint8]) -> None:
self.num_recent_undetected_frames = 0
self.tracked = detection.scaled_to_fit_image(bgr)
self.tracker = cv.TrackerCSRT_create()
self.tracker = cv2.TrackerCSRT_create()
bbox_xywh_rounded = [int(val) for val in self.tracked.bbox_xywh]
self.tracker.init(bgr, bbox_xywh_rounded)
self.log_tracked()
Expand Down Expand Up @@ -320,7 +320,7 @@ def track_objects(video_path: str) -> None:
detector = Detector(coco_categories=coco_categories)

logging.info("Loading input video: %s", str(video_path))
cap = cv.VideoCapture(video_path)
cap = cv2.VideoCapture(video_path)
frame_idx = 0

label_strs = [cat["name"] or str(cat["id"]) for cat in coco_categories]
Expand All @@ -333,7 +333,7 @@ def track_objects(video_path: str) -> None:
logging.info("End of video")
break

rgb = cv.cvtColor(bgr, cv.COLOR_BGR2RGB)
rgb = cv2.cvtColor(bgr, cv2.COLOR_BGR2RGB)
rr.log_image("image/rgb", rgb)

if not trackers or frame_idx % 40 == 0:
Expand Down Expand Up @@ -373,18 +373,14 @@ def setup_looging() -> None:
rerun_handler = rr.log.text.LoggingHandler("logs")
rerun_handler.setLevel(-1)
logger.addHandler(rerun_handler)
stream_handler = logging.StreamHandler()
stream_handler.setLevel(1)
logger.addHandler(stream_handler)
logger.setLevel(-1)


def main() -> None:
# Ensure the logging gets written to stderr:
logging.getLogger().addHandler(logging.StreamHandler())
logging.getLogger().setLevel("INFO")
logging.getLogger().setLevel("DEBUG")

parser = argparse.ArgumentParser(description="Logs Objectron data using the Rerun SDK.")
parser = argparse.ArgumentParser(description="Example applying simple object detection and tracking on a video.")
parser.add_argument(
"--video",
type=str,
Expand Down
2 changes: 1 addition & 1 deletion scripts/run_python_e2e_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@


def main() -> None:
parser = argparse.ArgumentParser(description="Logs Objectron data using the Rerun SDK.")
parser = argparse.ArgumentParser(description="Runs end-to-end tests of select python example.")
parser.add_argument("--no-build", action="store_true", help="Skip building rerun-sdk")
parser.add_argument("--no-pip-reqs", action="store_true", help="Skip installing pip requirements")

Expand Down