Squeeze#

class deeptrack.features.Squeeze(axis: int | tuple[int, ...] | None | Callable[[...], int | tuple[int, ...] | None] = None, **kwargs: Any)#

Bases: Feature

Squeeze the input array or tensor to the smallest possible dimension.

Squeeze removes axes of size 1 from the input array or tensor. By default, it removes all singleton dimensions. If a specific axis or axes are specified, only those axes are squeezed.

Parameters#

axis: int | tuple[int, …], optional

The axis or axes to squeeze. Defaults to None, squeezing all axes.

**kwargs: Any

Additional keyword arguments passed to the parent Feature class.

Methods#

get(inputs, axis, **kwargs) -> array

Squeeze the input array or tensor by removing singleton dimensions. The input and output can be a NumPy array or a PyTorch tensor.

Examples#

>>> import deeptrack as dt

Create an input array with extra dimensions:

>>> import numpy as np
>>>
>>> input_array = np.array([[[[1], [2], [3]]]])
>>> input_array.shape
(1, 1, 3, 1)

Create a Squeeze feature:

>>> squeeze_feature = dt.Squeeze(axis=0)
>>> output_array = squeeze_feature(input_array)
>>> output_array.shape
(1, 3, 1)

Without specifying an axis:

>>> squeeze_feature = dt.Squeeze()
>>> output_array = squeeze_feature(input_array)
>>> output_array.shape
(3,)

Methods Summary

get(inputs[, axis])

Squeeze the input array or tensor by removing singleton dimensions.

Methods Documentation

get(inputs: ndarray | Tensor, axis: int | tuple[int, ...] | None = None, **kwargs: Any) ndarray | Tensor#

Squeeze the input array or tensor by removing singleton dimensions.

Parameters#

inputs: array or tensor

The input array or tensor to process. The input can be a NumPy array or a PyTorch tensor.

axis: int or tuple[int, …], optional

The axis or axes to squeeze. Defaults to None, which squeezes all singleton axes.

**kwargs: Any

Additional keyword arguments (unused here).

Returns#

array or tensor

The squeezed array or tensor with reduced dimensions. The output can be a NumPy array or a PyTorch tensor.