-
Notifications
You must be signed in to change notification settings - Fork 398
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
Introduce IDL-based Tensor/Image APIs for python. #3188
Changes from 11 commits
0f99f9b
7a50aea
c391a84
8545df6
f29498a
d601fbe
9ecceca
9e393d6
fa535b9
71e14f3
8554095
f2af9f5
dcd01eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
"""Create and log an image.""" | ||
|
||
import numpy as np | ||
import rerun as rr | ||
import rerun.experimental as rr2 | ||
|
||
# Create an image with numpy | ||
image = np.zeros((200, 300, 3), dtype=np.uint8) | ||
image[:, :, 0] = 255 | ||
image[50:150, 50:150] = (0, 255, 0) | ||
|
||
rr.init("rerun_example_images", spawn=True) | ||
|
||
rr2.log("simple", rr2.Image(image)) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from __future__ import annotations | ||
|
||
from typing import TYPE_CHECKING | ||
|
||
from rerun.log.error_utils import _send_warning | ||
|
||
from ...datatypes import TensorDataArray | ||
|
||
if TYPE_CHECKING: | ||
from ...datatypes import TensorDataArrayLike | ||
|
||
|
||
def image_data_converter(data: TensorDataArrayLike) -> TensorDataArray: | ||
tensor_data = TensorDataArray.from_similar(data) | ||
|
||
# TODO(jleibs): Doing this on raw arrow data is not great. Clean this up | ||
# once we coerce to a canonical non-arrow type. | ||
shape = tensor_data[0].value["shape"].values.field(0).to_numpy() | ||
non_empty_dims = [d for d in shape if d != 1] | ||
num_non_empty_dims = len(non_empty_dims) | ||
|
||
# TODO(jleibs): What `recording` should we be passing here? How should we be getting it? | ||
if num_non_empty_dims < 2 or 3 < num_non_empty_dims: | ||
_send_warning(f"Expected image, got array of shape {shape}", 1, recording=None) | ||
|
||
if num_non_empty_dims == 3: | ||
depth = shape[-1] | ||
if depth not in (1, 3, 4): | ||
_send_warning( | ||
f"Expected image depth of 1 (gray), 3 (RGB) or 4 (RGBA). Instead got array of shape {shape}", | ||
1, | ||
recording=None, | ||
) | ||
|
||
# TODO(jleibs): The rust code labels the tensor dimensions as well. Would be nice to do something | ||
# similar here if they are unnamed. | ||
|
||
# TODO(jleibs): Should we enforce specific names on images? Specifically, what if the existing names are wrong. | ||
|
||
return tensor_data |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from __future__ import annotations | ||
|
||
from typing import Any | ||
|
||
import numpy as np | ||
import numpy.typing as npt | ||
|
||
|
||
def tensorbuffer_inner_converter(inner: npt.ArrayLike) -> npt.NDArray[Any]: | ||
# A tensor buffer is always a flat array | ||
return np.asarray(inner).flatten() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to
image_simple.py
once rebased!