returnn.frontend.types
#
Types
- class returnn.frontend.types.Tensor(name: str, dims: ~typing.Sequence[~returnn.tensor.dim.Dim] | None = None, dtype: str | None = None, *, sparse_dim: ~returnn.tensor.dim.Dim | None = None, feature_dim: ~returnn.tensor.dim.Dim | None = None, feature_dim_axis: int | ~returnn.util.basic.NotSpecified | None = <class 'returnn.util.basic.NotSpecified'>, raw_tensor: ~returnn.tensor.tensor.RawTensorType | None = None, version: int | None = None, **kwargs)[source]#
Represents a tensor, in a frame-agnostic way. See the module docstring.
- Parameters:
name –
dims – the shape, where each dimension is described by a
Dim
.dtype – e.g. “float32” or “int64”
sparse_dim – when the values are indices into some dimension, this is the dimension. You can also interpret the whole tensor as a sparse representation of a dense one-hot tensor, where this sparse_dim becomes the additional dense dimension.
raw_tensor – the raw tensor, e.g. numpy array, TF tensor, or PyTorch tensor
version –
behavior version just for Tensor. If not specified, and dims is None (old code), it uses version 1. - v1: the old behavior of Data. Specifically, time_dim_axis and feature_dim_axis are used
and automatically inferred when not specified.
v2: time_dim_axis, feature_dim_axis are None by default.
kwargs – see
_handle_extra_kwargs()
,infer_dim_tags()
- property dims_set: Set[Dim][source]#
- Returns:
set of dim tags. in all high-level code, the order of dims is irrelevant. The order must not play a role (RETURNN principles: https://github.com/rwth-i6/returnn/wiki/RETURNN-principles). Note that we do not include any implicit dims here. Also see
verify_out_shape()
and https://github.com/rwth-i6/returnn/issues/1153.
- property feature_dim: Dim | None[source]#
- Returns:
self.dims[self.feature_dim_axis] or None. See https://github.com/rwth-i6/returnn/issues/1273 for some discussion.
- class returnn.frontend.types.Dim(dimension: int | Tensor | None, *, name: str | None = None, capacity: int | None = None, dyn_size_ext: Tensor | None = None, description: str | None = None, **kwargs)[source]#
Represents a dimension of a tensor. This potentially comes with further information such as individual sequence lengths. See the module docstring.