ARTICLE DETAIL

资讯详情

深耕网站建设与运营推广的一线实战洞察。

Rerun `TensorWidthDimension` 组件详解:张量宽度维度的选择、编码与查看器自动校验

Rerun `TensorWidthDimension` 组件详解:张量宽度维度的选择、编码与查看器自动校验 RerunTensorWidthDimension组件详解张量宽度维度的选择、编码与查看器自动校验【免费下载链接】rerunVisualize, query, and stream to train on multimodal robotics data.项目地址: https://gitcode.com/GitHub_Trending/re/rerunTensorWidthDimension是 Rerun 数据类型系统中用于指定「将张量Tensor的哪一个维度映射为宽度」的蓝图组件。它是TensorSliceSelection张量二维切片选择蓝图原型的关键组成之一配合TensorHeightDimension、TensorDimensionIndexSelection与滑块组件共同决定 Tensor 视图re_view_tensor中如何从 N 维张量中切出可视化的 2D 切片。阅读本文后你将掌握该组件的字段语义、底层编码TensorDimensionSelection、Arrow 序列化格式以及查看器端如何对越界维度进行钳制与自动回退并能在 Python / Rust / C SDK 中正确使用它。组件定位从 N 维张量到 2D 视图Rerun 的 Tensor 视图负责可视化 N 维张量数据。为了把高维数据展示在屏幕上查看器必须先把张量「切」成一个 2D 切片——其中一个维度映射到宽度width一个维度映射到高度height其余维度通过索引或滑块固定取值。TensorWidthDimension正是承担「指定宽度维度」这一职责的组件。在类型定义文件中它与高度组件成对出现// crates/build/re_type_definitions/rerun/components/tensor_dimension_selection.def.rs /// Specifies which dimension to use for height. #[rerun(state stable)] pub struct TensorHeightDimension { pub dimension: rerun::encodings::TensorDimensionSelection, } /// Specifies which dimension to use for width. #[rerun(state stable)] pub struct TensorWidthDimension { pub dimension: rerun::encodings::TensorDimensionSelection, }两个组件结构完全一致仅语义不同均被标记为stable稳定状态并作为TensorSliceSelection蓝图原型的可选字段Option存在——也就是说宽度维度可以不显式指定交由查看器自动推断详见下文「自动校验与回退」。字段语义dimension与invertTensorWidthDimension本身没有自有字段它直接委托给底层编码TensorDimensionSelection。在 TensorDimensionSelection 编码文档 中该结构包含两个字段字段类型语义dimension非空UInt32要选择的维度编号从 0 开始的轴索引invert非空Boolean是否反转该维度的方向其中dimension是核心它指明张量的第几个轴axis映射为宽度。invert用于坐标轴方向校正——例如相机坐标系中图像行方向通常向下而在某些可视化约定中宽度方向需要与「左/右」对齐此时置invert true可反转该轴的方向。类型定义源文件 tensor_dimension_selection.def.rs 还给出了一个直观的注释示例dimension2、index42的选择等价于 NumPy 中的tensor[:, :, 42, :, :, …]——这正是同族组件TensorDimensionIndexSelection的用法而宽度/高度组件只关心维度号本身。Rerun 编码TensorDimensionSelectionTensorWidthDimension是「组件Component」其数据载体是「编码Encoding」TensorDimensionSelection。在 Rust 侧组件通过WrapperComponent包装编码// crates/store/re_sdk_types/src/components/tensor_width_dimension.rs #[derive(Clone, Debug, Hash, Copy, PartialEq, Eq, Default, ::re_byte_size::SizeBytes)] #[repr(transparent)] pub struct TensorWidthDimension(pub crate::encodings::TensorDimensionSelection); impl ::re_types_core::WrapperComponent for TensorWidthDimension { type Encoding crate::encodings::TensorDimensionSelection; fn name() - ComponentType { rerun.components.TensorWidthDimension.into() } // ... }该文件头部注释明确说明它由re_types_builder代码生成器自动生成源头正是前文引用的.def.rs类型定义。组件名称为rerun.components.TensorWidthDimension是 Rerun 协议中的正式标识。为了方便使用SDK 提供了便捷构造RustFromu32允许直接用整数构造invert自动取false见 tensor_dimension_selection_ext.rsimpl Fromu32 for TensorDimensionSelection { fn from(dimension: u32) - Self { Self { dimension, invert: false } } }因此在 Rust 中TensorWidthDimension::from(0)即表示「第 0 维作为宽度、不反转」。Python类型定义中标注了#[python(aliases int)]与#[python(array_aliases npt.ArrayLike)]意味着 Python API 允许直接传整数或 NumPy 数组来构造例如rr.components.TensorWidthDimension(dimension0)或直接传0。C与 Rust / Python 一样由同一份.def.rs经re_types_builder生成对应绑定。Arrow 数据类型与序列化TensorWidthDimension在 Rerun 存储层以 Arrow 格式序列化。其 Arrow 数据类型是一个结构体StructStruct( dimension: non-null UInt32 invert: non-null Boolean )这个布局在编码的 Rust 实现 tensor_dimension_selection.rs 中可逐行印证arrow_data_type()返回DataType::Struct(Fields::from(vec![Field::new(dimension, DataType::UInt32, false), Field::new(invert, DataType::Boolean, false)]))ToArrow序列化时分别生成UInt32Array与BooleanArray两个子列并打包进StructArrayFromArrow反序列化时则按字段名查找子数组缺失任一字段都会报missing_struct_field错误。两个字段均非空non-null反序列化时还会通过err_on_nulls拒绝空值保证数据完整性。在TensorSliceSelection蓝图原型中的角色TensorWidthDimension不是独立使用的组件而是TensorSliceSelection蓝图原型的组成部分。在类型定义 tensor_slice_selection.def.rs 中该原型状态为unstable作用域为blueprint包含四个可选字段width: OptionTensorWidthDimension——哪个维度映射到宽度未指定时根据维度名称与索引自动推断height: OptionTensorHeightDimension——哪个维度映射到高度indices: OptionVecTensorDimensionIndexSelection——其余各维选定的索引若与width/height重复则被忽略slider——需要出现索引滑块的维度列表滑块编辑会直接写回indices。也就是说想要在 Python 中为 Tensor 视图指定宽度维度通常是构建/修改TensorSliceSelection蓝图原型设置其中的width字段类型即TensorWidthDimension而非单独记录该组件。该组件在数据模型中本身是「组件」蓝图原型则把它与高度、索引、滑块组织成一个完整的 2D 切片描述。查看器端的自动校验与回退视图端re_view_tensorcrate在加载蓝图切片选择时会进行「清洗scrubbing」以保证选择对当前张量形状有效。核心逻辑位于 dimension_mapping.rs 的TensorSliceSelection::load_and_make_valid其通用规则为越界钳制dimension超过张量有效轴范围时被钳制到shape.len() - 1最大有效维号宽度/高度冲突处理若width.dimension height.dimension则移除高度height.take()视作未设置自动回退当张量至少有 2 个维度时强制宽度与高度都存在若缺失则调用find_width_height_dim_indices依据维度名称推断——宽度默认取名为left的轴若名称匹配left还会自动设置invert true高度默认取名为up的轴并相应设置invert。这段逻辑直接印证了invert字段的实际用途它服务于「方向」语义——当宽度维度恰好是名为left的轴时查看器会自动反转其方向使可视化坐标系与张量存储方向正确对齐。用户显式设置的TensorWidthDimension同样经过这套钳制与去重流程保证最终切片选择对任意形状的张量都有效。跨语言 API 速览三种官方 SDK 均提供TensorWidthDimension组件其 Python 侧生成代码见 tensor_width_dimension.pyTensorWidthDimension直接继承encodings.TensorDimensionSelection并混入ComponentMixin配合TensorWidthDimensionBatch以批量方式参与日志/蓝图序列化。典型用法模式Pythonrr.blueprint.archetypes.TensorSliceSelection(widthrr.components.TensorWidthDimension(dimension0))dimension与invert均可直接传参RustTensorSliceSelection::new().with_width(TensorWidthDimension::from(0))Fromu32让整数直接可用C与上述两语言同一套命名与字段约定rerun::components::TensorWidthDimension。原始参考文档 tensor_width_dimension.md 末尾为各语言提供了对应的 API 文档入口分别指向 Cstable 分支头文件文档、Pythonrerun.components.TensorWidthDimension与 Rustrerun::components::TensorWidthDimension的组件说明页便于按语言查阅更细的构造与使用示例。小结TensorWidthDimension是 Rerun Tensor 可视化链路中一个「小而关键」的组件它以TensorDimensionSelectiondimension: u32invert: bool为编码以非空 Struct 形式的 Arrow 数据类型存储隶属于TensorSliceSelection蓝图原型并配合查看器端的钳制、去重与基于维度名称的自动回退逻辑让开发者只需极少的显式配置即可获得正确的张量切片视图。理解它的字段语义与底层实现有助于在自定义 Tensor 可视化流程中精准控制切片映射行为。【免费下载链接】rerunVisualize, query, and stream to train on multimodal robotics data.项目地址: https://gitcode.com/GitHub_Trending/re/rerun创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表