Unsqueeze#
- class deeptrack.features.Unsqueeze(axis: int | tuple[int, ...] | None | Callable[[...], int | tuple[int, ...] | None] = -1, **kwargs: Any)#
Bases:
FeatureUnsqueeze the input array or tensor to the smallest possible dimension.
This feature adds new singleton dimensions to the input array or tensor at the specified axis or axes. Defaults to adding a singleton dimension at the last axis if no axis is specified.
Parameters#
- axis: PropertyLike[int | tuple[int, …]], optional
The axis or axes where new singleton dimensions should be added. Defaults to None, which adds a singleton dimension at the last axis.
- **kwargs: Any
Additional keyword arguments passed to the parent Feature class.
Methods#
- get(inputs, axis, **kwargs) -> array or tensor
Add singleton dimensions to the input array or tensor. The input and output can be a NumPy array or a PyTorch tensor.
Examples#
>>> import deeptrack as dt
Create an input array:
>>> import numpy as np >>> >>> input_array = np.array([1, 2, 3]) >>> input_array.shape (3,)
Apply Unsqueeze feature:
>>> unsqueeze_feature = dt.Unsqueeze(axis=0) >>> output_array = unsqueeze_feature(input_array) >>> output_array.shape (1, 3)
Without specifying an axis, in unsqueezes the last dimension:
>>> unsqueeze_feature = dt.Unsqueeze() >>> output_array = unsqueeze_feature(input_array) >>> output_array.shape (3, 1)
Methods Summary
get(inputs[, axis])Add singleton dimensions to the input image.
Methods Documentation
- get(inputs: ndarray | Tensor, axis: int | tuple[int, ...] | None = -1, **kwargs: Any) ndarray | Tensor#
Add singleton dimensions to the input image.
Parameters#
- image: array
The input array or tensor to process. The input array can be a NumPy array or a PyTorch tensor.
- axis: int or tuple[int, …], optional
The axis or axes where new singleton dimensions should be added. It defaults to -1, which adds a singleton dimension at the last axis.
- **kwargs: Any
Additional keyword arguments (unused here).
Returns#
- array or tensor
The input array or tensor with the specified singleton dimensions added. The output can be a NumPy array, or a PyTorch tensor.