Struct re_components::Tensor
source · pub struct Tensor {
pub tensor_id: TensorId,
pub shape: Vec<TensorDimension>,
pub data: TensorData,
pub meaning: TensorDataMeaning,
pub meter: Option<f32>,
}
Expand description
A Multi-dimensional Tensor.
All clones are shallow.
The Tensor
component is special, as you can only have one instance of it per entity.
This is because each element in a tensor is considered to be a separate instance.
Examples
assert_eq!(
Tensor::data_type(),
DataType::Struct(vec![
Field::new("tensor_id", DataType::FixedSizeBinary(16), false),
Field::new(
"shape",
DataType::List(Box::new(Field::new(
"item",
TensorDimension::data_type(),
false
)),),
false
),
Field::new("data", TensorData::data_type(), false),
Field::new(
"meaning",
DataType::Union(
vec![
Field::new("Unknown", DataType::Boolean, false),
Field::new("ClassId", DataType::Boolean, false),
Field::new("Depth", DataType::Boolean, false)
],
None,
UnionMode::Dense
),
false
),
Field::new("meter", DataType::Float32, true),
])
);
Fields§
§tensor_id: TensorId
Unique identifier for the tensor
shape: Vec<TensorDimension>
Dimensionality and length
data: TensorData
Data payload
meaning: TensorDataMeaning
The per-element data meaning Used to indicated if the data should be interpreted as color, class_id, etc.
meter: Option<f32>
Reciprocal scale of meter unit for depth images
Implementations§
source§impl Tensor
impl Tensor
pub fn id(&self) -> TensorId
pub fn shape(&self) -> &[TensorDimension]
sourcepub fn shape_short(&self) -> &[TensorDimension]
pub fn shape_short(&self) -> &[TensorDimension]
Returns the shape of the tensor with all trailing dimensions of size 1 ignored.
If all dimension sizes are one, this returns only the first dimension.
pub fn num_dim(&self) -> usize
sourcepub fn image_height_width_channels(&self) -> Option<[u64; 3]>
pub fn image_height_width_channels(&self) -> Option<[u64; 3]>
If the tensor can be interpreted as an image, return the height, width, and channels/depth of it.
sourcepub fn is_shaped_like_an_image(&self) -> bool
pub fn is_shaped_like_an_image(&self) -> bool
Returns true if the tensor can be interpreted as an image.
sourcepub fn is_vector(&self) -> bool
pub fn is_vector(&self) -> bool
Returns true if either all dimensions have size 1 or only a single dimension has a size larger than 1.
Empty tensors return false.
pub fn meaning(&self) -> TensorDataMeaning
sourcepub fn get_with_image_coords(
&self,
x: u64,
y: u64,
channel: u64
) -> Option<TensorElement>
pub fn get_with_image_coords( &self, x: u64, y: u64, channel: u64 ) -> Option<TensorElement>
Query with x, y, channel indices.
Allows to query values for any image like tensor even if it has more or less dimensions than 3.
(useful for sampling e.g. N x M x C x 1
tensor which is a valid image)
pub fn get(&self, index: &[u64]) -> Option<TensorElement>
pub fn dtype(&self) -> TensorDataType
pub fn size_in_bytes(&self) -> usize
source§impl Tensor
impl Tensor
pub fn new( tensor_id: TensorId, shape: Vec<TensorDimension>, data: TensorData, meaning: TensorDataMeaning, meter: Option<f32> ) -> Self
source§impl Tensor
impl Tensor
sourcepub fn from_image_file(path: &Path) -> Result<Self, TensorImageLoadError>
pub fn from_image_file(path: &Path) -> Result<Self, TensorImageLoadError>
Construct a tensor from the contents of an image file on disk.
JPEGs will be kept encoded, left to the viewer to decode on-the-fly. Other images types will be decoded directly.
Requires the image
feature.
sourcepub fn from_jpeg_file(path: &Path) -> Result<Self, TensorImageLoadError>
pub fn from_jpeg_file(path: &Path) -> Result<Self, TensorImageLoadError>
Construct a tensor from the contents of a JPEG file on disk.
Requires the image
feature.
pub fn tensor_from_jpeg_file( image_path: impl AsRef<Path> ) -> Result<Self, TensorImageLoadError>
sourcepub fn from_image_bytes(
bytes: Vec<u8>,
format: ImageFormat
) -> Result<Self, TensorImageLoadError>
pub fn from_image_bytes( bytes: Vec<u8>, format: ImageFormat ) -> Result<Self, TensorImageLoadError>
Construct a tensor from the contents of an image file.
JPEGs will be kept encoded, left to the viewer to decode on-the-fly. Other images types will be decoded directly.
Requires the image
feature.
sourcepub fn from_jpeg_bytes(
jpeg_bytes: Vec<u8>
) -> Result<Self, TensorImageLoadError>
pub fn from_jpeg_bytes( jpeg_bytes: Vec<u8> ) -> Result<Self, TensorImageLoadError>
Construct a tensor from the contents of a JPEG file, without decoding it now.
Requires the image
feature.
pub fn tensor_from_jpeg_bytes( jpeg_bytes: Vec<u8> ) -> Result<Self, TensorImageLoadError>
sourcepub fn from_image(
image: impl Into<DynamicImage>
) -> Result<Tensor, TensorImageLoadError>
pub fn from_image( image: impl Into<DynamicImage> ) -> Result<Tensor, TensorImageLoadError>
Construct a tensor from something that can be turned into a image::DynamicImage
.
Requires the image
feature.
This is a convenience function that calls DecodedTensor::from_image
.
sourcepub fn from_dynamic_image(
image: DynamicImage
) -> Result<Tensor, TensorImageLoadError>
pub fn from_dynamic_image( image: DynamicImage ) -> Result<Tensor, TensorImageLoadError>
Construct a tensor from image::DynamicImage
.
Requires the image
feature.
This is a convenience function that calls DecodedTensor::from_dynamic_image
.
sourcepub fn could_be_dynamic_image(&self) -> bool
pub fn could_be_dynamic_image(&self) -> bool
Predicts if Self::to_dynamic_image
is likely to succeed, without doing anything expensive
sourcepub fn to_dynamic_image(&self) -> Result<DynamicImage, TensorImageSaveError>
pub fn to_dynamic_image(&self) -> Result<DynamicImage, TensorImageSaveError>
Try to convert an image-like tensor into an image::DynamicImage
.
Trait Implementations§
source§impl ArrowDeserialize for Tensor
impl ArrowDeserialize for Tensor
source§impl ArrowField for Tensor
impl ArrowField for Tensor
source§impl ArrowSerialize for Tensor
impl ArrowSerialize for Tensor
§type MutableArrayType = MutableTensorArray
type MutableArrayType = MutableTensorArray
arrow2::array::MutableArray
that holds this valuesource§fn new_array() -> Self::MutableArrayType
fn new_array() -> Self::MutableArrayType
source§fn arrow_serialize(v: &Self, array: &mut Self::MutableArrayType) -> Result<()>
fn arrow_serialize(v: &Self, array: &mut Self::MutableArrayType) -> Result<()>
source§impl AsRef<Tensor> for DecodedTensor
impl AsRef<Tensor> for DecodedTensor
source§impl Borrow<Tensor> for DecodedTensor
impl Borrow<Tensor> for DecodedTensor
source§impl LegacyComponent for Tensor
impl LegacyComponent for Tensor
source§fn legacy_name() -> ComponentName
fn legacy_name() -> ComponentName
source§impl Loggable for Tensor
impl Loggable for Tensor
type Name = ComponentName
type Item<'a> = <&'a <Tensor as ArrowDeserialize>::ArrayType as IntoIterator>::Item
type Iter<'a> = <&'a <Tensor as ArrowDeserialize>::ArrayType as IntoIterator>::IntoIter
source§fn name() -> Self::Name
fn name() -> Self::Name
rerun.datatypes.Vec2D
.source§fn to_arrow_datatype() -> DataType
fn to_arrow_datatype() -> DataType
arrow2::datatypes::DataType
.source§fn try_to_arrow_opt<'a>(
data: impl IntoIterator<Item = Option<impl Into<Cow<'a, Self>>>>,
_extension_wrapper: Option<&str>
) -> SerializationResult<Box<dyn Array>>where
Self: Clone + 'a,
fn try_to_arrow_opt<'a>( data: impl IntoIterator<Item = Option<impl Into<Cow<'a, Self>>>>, _extension_wrapper: Option<&str> ) -> SerializationResult<Box<dyn Array>>where Self: Clone + 'a,
Loggable
, serializes them into an Arrow array.
The Arrow array’s datatype will match Loggable::to_arrow_datatype
. Read moresource§fn try_iter_from_arrow(
data: &dyn Array
) -> DeserializationResult<Self::Iter<'_>>where
Self: Sized,
fn try_iter_from_arrow( data: &dyn Array ) -> DeserializationResult<Self::Iter<'_>>where Self: Sized,
Loggable::Item
s. Read moresource§fn convert_item_to_self(item: Self::Item<'_>) -> Option<Self>
fn convert_item_to_self(item: Self::Item<'_>) -> Option<Self>
source§fn to_arrow<'a>(
data: impl IntoIterator<Item = impl Into<Cow<'a, Self>>>,
extension_wrapper: Option<&str>
) -> Box<dyn Array, Global>where
Self: Clone + 'a,
fn to_arrow<'a>( data: impl IntoIterator<Item = impl Into<Cow<'a, Self>>>, extension_wrapper: Option<&str> ) -> Box<dyn Array, Global>where Self: Clone + 'a,
Loggable
, serializes
them into an Arrow array.
The Arrow array’s datatype will match Loggable::to_arrow_datatype
. Read moresource§fn try_to_arrow<'a>(
data: impl IntoIterator<Item = impl Into<Cow<'a, Self>>>,
extension_wrapper: Option<&str>
) -> Result<Box<dyn Array, Global>, SerializationError>where
Self: Clone + 'a,
fn try_to_arrow<'a>( data: impl IntoIterator<Item = impl Into<Cow<'a, Self>>>, extension_wrapper: Option<&str> ) -> Result<Box<dyn Array, Global>, SerializationError>where Self: Clone + 'a,
Loggable
, serializes
them into an Arrow array.
The Arrow array’s datatype will match Loggable::to_arrow_datatype
. Read moresource§fn to_arrow_opt<'a>(
data: impl IntoIterator<Item = Option<impl Into<Cow<'a, Self>>>>,
extension_wrapper: Option<&str>
) -> Box<dyn Array, Global>where
Self: Clone + 'a,
fn to_arrow_opt<'a>( data: impl IntoIterator<Item = Option<impl Into<Cow<'a, Self>>>>, extension_wrapper: Option<&str> ) -> Box<dyn Array, Global>where Self: Clone + 'a,
Loggable
, serializes them into an Arrow array.
The Arrow array’s datatype will match Loggable::to_arrow_datatype
. Read more