Skip to content

Commit

Permalink
Pylints and pass the unit through to the viewer.
Browse files Browse the repository at this point in the history
  • Loading branch information
zrezke committed Feb 23, 2024
1 parent b07696f commit dd10b91
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 20 deletions.
7 changes: 5 additions & 2 deletions crates/re_viewer/src/ui/data_ui/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,8 +568,11 @@ fn tensor_pixel_value_ui(
_ => {
match &tensor.unit {
Some(unit) => {
println!("Unit: {unit}");
tensor.get(&[y, x]).map(|v| format!("Val: {v} {unit}"))
if tensor.dtype().is_float() {
tensor.get(&[y, x]).map(|v| format!("Val: {v:.2} {unit}"))
} else {
tensor.get(&[y, x]).map(|v| format!("Val: {v} {unit}"))
}
},
None => {
tensor.get(&[y, x]).map(|v| format!("Val: {v}"))
Expand Down
2 changes: 1 addition & 1 deletion rerun_py/depthai_viewer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import depthai_viewer_bindings as bindings # type: ignore[attr-defined]

from depthai_viewer import _backend
from depthai_viewer.components.tensor import ImageEncoding, Colormap
from depthai_viewer.components.tensor import Colormap, ImageEncoding
from depthai_viewer.log import log_cleared
from depthai_viewer.log.annotation import (
AnnotationInfo,
Expand Down
5 changes: 4 additions & 1 deletion rerun_py/depthai_viewer/_backend/config_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ async def main(port: int = 9001) -> None:


def start_api(
_dispatch_action_queue: Queue, _result_queue: Queue, _send_message_queue: Queue, port: int = 9001 # type: ignore[type-arg]
_dispatch_action_queue: Queue, # type: ignore[type-arg]
_result_queue: Queue, # type: ignore[type-arg]
_send_message_queue: Queue, # type: ignore[type-arg]
port: int = 9001,
) -> None:
"""
Starts the websocket API.
Expand Down
6 changes: 3 additions & 3 deletions rerun_py/depthai_viewer/_backend/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
get_size_from_resolution,
size_to_resolution,
)
from depthai_viewer._backend.device_defaults import oak_t_default
from depthai_viewer._backend.messages import (
ErrorMessage,
InfoMessage,
Expand All @@ -40,7 +41,6 @@
)
from depthai_viewer._backend.packet_handler import PacketHandler
from depthai_viewer._backend.store import Store
from depthai_viewer._backend.device_defaults import oak_t_default


class XlinkStatistics:
Expand Down Expand Up @@ -526,10 +526,10 @@ def update_pipeline(self, runtime_only: bool) -> Message:
self.store.send_message_to_frontend(
WarningMessage(f"{config.ai_model.camera} is not configured, won't create NNET.")
)
if cam_component and config.ai_model and config.ai_model.path == "age-gender-recognition-retail-0013":
elif config.ai_model.path == "age-gender-recognition-retail-0013":
face_detection = self._oak.create_nn("face-detection-retail-0004", cam_component)
self._nnet = self._oak.create_nn("age-gender-recognition-retail-0013", input=face_detection)
elif cam_component:
else:
self._nnet = self._oak.create_nn(config.ai_model.path, cam_component)
if self._nnet:
self._queues.append((self._nnet, self._oak.queue(self._nnet.out.main)))
Expand Down
10 changes: 6 additions & 4 deletions rerun_py/depthai_viewer/_backend/device_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def to_runtime_controls(self) -> Dict[str, Any]:
"align": (
"RECTIFIED_LEFT"
if self.align == dai.CameraBoardSocket.LEFT
else "RECTIFIED_RIGHT" if self.align == dai.CameraBoardSocket.RIGHT else "CENTER"
else "RECTIFIED_RIGHT"
if self.align == dai.CameraBoardSocket.RIGHT
else "CENTER"
),
"lr_check": self.lr_check,
"lrc_check_threshold": self.lrc_threshold,
Expand Down Expand Up @@ -270,9 +272,9 @@ class DeviceProperties(BaseModel): # type: ignore[misc]
id: str
cameras: List[CameraFeatures] = []
imu: Optional[ImuKind]
stereo_pairs: List[Tuple[dai.CameraBoardSocket, dai.CameraBoardSocket]] = (
[]
) # Which cameras can be paired for stereo
stereo_pairs: List[
Tuple[dai.CameraBoardSocket, dai.CameraBoardSocket]
] = [] # Which cameras can be paired for stereo
default_stereo_pair: Optional[Tuple[dai.CameraBoardSocket, dai.CameraBoardSocket]] = None
info: DeviceInfo = DeviceInfo()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import depthai as dai
from depthai_viewer._backend.device_configuration import (
PipelineConfiguration,
CameraConfiguration,
CameraSensorResolution,
PipelineConfiguration,
)
import depthai as dai

config = PipelineConfiguration(
cameras=[
Expand Down
1 change: 0 additions & 1 deletion rerun_py/depthai_viewer/_backend/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import sentry_sdk

import depthai_viewer as viewer
from depthai_viewer import version as depthai_viewer_version
from depthai_viewer._backend.config_api import Action, start_api
from depthai_viewer._backend.device import Device
Expand Down
2 changes: 1 addition & 1 deletion rerun_py/depthai_viewer/_backend/packet_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def _on_camera_frame(self, packet: FramePacket, board_socket: dai.CameraBoardSoc
)
elif packet.msg.getType() == dai.RawImgFrame.Type.GRAYF16:
img = img_frame.view(np.float16).reshape(h, w)
viewer.log_image(entity_path, img, colormap=viewer.Colormap.Magma, unit="degrees ")
viewer.log_image(entity_path, img, colormap=viewer.Colormap.Magma, unit="°C")
else:
viewer.log_image(entity_path, img_frame)

Expand Down
2 changes: 1 addition & 1 deletion rerun_py/depthai_viewer/components/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def from_numpy(
else:
meter = pa.array([meter], mask=[False], type=pa.float32())

unit = pa.array(["string" if unit is not None else ""], type=pa.string())
unit = pa.array([unit if unit is not None else ""], type=pa.string())

storage = pa.StructArray.from_arrays(
[tensor_id, shape, data, meaning, meter, colormap, unit],
Expand Down
8 changes: 6 additions & 2 deletions rerun_py/depthai_viewer/log/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import numpy as np
import numpy.typing as npt
from enum import Enum

from depthai_viewer import bindings
from depthai_viewer.components.tensor import ImageEncoding, Colormap
from depthai_viewer.components.tensor import Colormap, ImageEncoding
from depthai_viewer.log.error_utils import _send_warning
from depthai_viewer.log.log_decorator import log_decorator
from depthai_viewer.log.tensor import Tensor, _log_tensor, _to_numpy
Expand Down Expand Up @@ -46,6 +46,10 @@ def log_image(
Path to the image in the space hierarchy.
image:
A [Tensor][rerun.log.tensor.Tensor] representing the image to log.
colormap:
Optional colormap to apply to single channel images.
unit:
Optional unit of the single channel image.
ext:
Optional dictionary of extension components. See [rerun.log_extension_components][]
timeless:
Expand Down
5 changes: 3 additions & 2 deletions rerun_py/depthai_viewer/log/tensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from depthai_viewer import bindings
from depthai_viewer.components.instance import InstanceArray
from depthai_viewer.components.tensor import ImageEncoding, TensorArray, Colormap
from depthai_viewer.components.tensor import Colormap, ImageEncoding, TensorArray
from depthai_viewer.log.error_utils import _send_warning
from depthai_viewer.log.extension_components import _add_extension_components
from depthai_viewer.log.log_decorator import log_decorator
Expand All @@ -18,7 +18,8 @@
class TorchTensorLike(Protocol):
"""Describes what is need from a Torch Tensor to be loggable to Rerun."""

def numpy(self, force: bool) -> npt.NDArray[Any]: ...
def numpy(self, force: bool) -> npt.NDArray[Any]:
...


Tensor = Union[npt.ArrayLike, TorchTensorLike]
Expand Down

0 comments on commit dd10b91

Please sign in to comment.