nos.common.types
nos.common.types ¶
TensorSpec ¶
Source code in nos/common/types.py
shape
class-attribute
instance-attribute
¶
Base tensor specification with at most 4 dimensions.
This class is used to capture the shape and dtype of a tensor. Tensor shapes are specified as a tuple of integers, where the first dimension is the batch size. Each of the dimensions are optional, and can be set to None to support dynamic dimension. For e.g., a model that supports variable batch size has shape=(None, 224, 224, 3).
Examples:
ImageSpec: - (H, W, C): (height, width, channels) EmbeddingSpec: - (D): (dims, )
dtype
class-attribute
instance-attribute
¶
Tensor dtype. (uint8, int32, int64, float32, float64)
validate_shape
classmethod
¶
Validate the shape.
Source code in nos/common/types.py
validate_dtype
classmethod
¶
Validate the dtype.
ImageSpec ¶
Image tensor specification with dimensions (H, W, C).
Source code in nos/common/types.py
validate_shape
classmethod
¶
Validate the shape.
Source code in nos/common/types.py
EmbeddingSpec ¶
Embedding tensor specification with dimensions (D).
Source code in nos/common/types.py
validate_shape
classmethod
¶
Validate the shape.
Source code in nos/common/types.py
Batch ¶
Generic annotation/type-hint for batched data.
Inherits from typing.Annotated[T, x] (PEP 593) where T is the type, and x is the metadata. The metadata is tpyically ignored, but can be used to allow additional type checks and annotations on the type.
Source code in nos/common/types.py
__class_getitem__ ¶
Support Batch[T, batch_size].
Annotated requires atleast 2 parameters [type, metadata].
Here batch_size
is optional (i.e. Batch[T],
is equivalent to Batch[T, None]).
Source code in nos/common/types.py
TensorT ¶
Source code in nos/common/types.py
__class_getitem__ ¶
Support TensorT[type, tensor_spec].
Annotated requires atleast 2 parameters [type, tensor_spec].
Here tensor_spec
is optional (i.e. TensorT[T],
is equivalent to TensorT[T, None]).
Examples:
TensorT[np.ndarray, TensorSpec()] := Annotated[TensorT, np.ndarray, TensorSpec()] TensorT[torch.Tensor, TensorSpec()] := Annotated[TensorT, torch.Tensor, TensorSpec()]
Source code in nos/common/types.py
ImageT ¶
Source code in nos/common/types.py
__class_getitem__ ¶
Support TensorT[type, image_spec].
Annotated requires atleast 2 parameters [type, image_spec].
Here image_spec
is optional (i.e. ImageT[T], is equivalent to TensorT[T, ImageSpec()]).
Examples:
ImageT[PIL.Image.Image, ImageSpec()] := Annotated[ImageT, Image, ImageSpec()]