Transforms¶
Data transformation utilities for preprocessing and augmentation.
Overview¶
Transforms are used to preprocess images for training and inference with compression models.
transforms
¶
GeneratePositionNormals
¶
Bases: BaseTransform
Generates normals from node positions
(functional name: :obj:generate_position_normals).
NormalizeScaleV2
¶
Bases: BaseTransform
Centers and normalizes node positions
(functional name: :obj:normalize_scale_v2).
RandomPermutation
¶
Bases: BaseTransform
Randomly permutes points and associated attributes
(functional name: :obj:random_permutation).
RandomRotateFull
¶
Bases: BaseTransform
Randomly rotates node positions around the origin
(functional name: :obj:random_rotate_full).
RandomSample
¶
RandomSample(num=None, *, attrs=('pos',), remove_duplicates_by=None, preserve_order=False, seed=None, static_seed=None)
Bases: BaseTransform
Randomly samples points and associated attributes
(functional name: :obj:random_sample).
SamplePointsV2
¶
Bases: BaseTransform
Uniformly samples a fixed number of points on the mesh faces according
to their face area (functional name: :obj:sample_points).
Adapted from PyTorch Geometric under MIT license at https://github.com/pyg-team/pytorch_geometric/blob/master/LICENSE.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num
|
int
|
The number of points to sample. |
required |
remove_faces
|
bool
|
If set to :obj: |
True
|
include_normals
|
bool
|
If set to :obj: |
False
|
seed
|
int
|
Initial random seed. |
None
|
static_seed
|
int
|
Reset random seed to this every call. |
None
|
ToDict
¶
Bases: BaseTransform
Convert :obj:Mapping[str, Any]
(functional name: :obj:to_dict).
RGB2YCbCr
¶
Convert a RGB tensor to YCbCr. The tensor is expected to be in the [0, 1] floating point range, with a shape of (3xHxW) or (Nx3xHxW).
__call__
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rgb
|
Tensor
|
3D or 4D floating point RGB tensor |
required |
Returns:
| Name | Type | Description |
|---|---|---|
ycbcr |
Tensor
|
converted tensor |
YCbCr2RGB
¶
Convert a YCbCr tensor to RGB. The tensor is expected to be in the [0, 1] floating point range, with a shape of (3xHxW) or (Nx3xHxW).
__call__
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ycbcr
|
Tensor
|
3D or 4D floating point RGB tensor |
required |
Returns:
| Name | Type | Description |
|---|---|---|
rgb |
Tensor
|
converted tensor |
YUV444To420
¶
Convert a YUV 444 tensor to a 420 representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
algorithm used for downsampling: |
'avg_pool'
|
Example
x = torch.rand(1, 3, 32, 32) y, u, v = YUV444To420()(x) y.size() # 1, 1, 32, 32 u.size() # 1, 1, 16, 16
__call__
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
yuv
|
Tensor or (Tensor, Tensor, Tensor)
|
444 input to be downsampled. Takes either a (Nx3xHxW) tensor or a tuple of 3 (Nx1xHxW) tensors. |
required |
Returns:
| Type | Description |
|---|---|
(Tensor, Tensor, Tensor)
|
Converted 420 |
YUV420To444
¶
Convert a YUV 420 input to a 444 representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
str
|
algorithm used for upsampling: |
'bilinear'
|
return_tuple
|
bool
|
return input as tuple of tensors instead of a concatenated tensor, 3 (Nx1xHxW) tensors instead of one (Nx3xHxW) tensor (default: False) |
False
|
Example
y = torch.rand(1, 1, 32, 32) u, v = torch.rand(1, 1, 16, 16), torch.rand(1, 1, 16, 16) x = YUV420To444()((y, u, v)) x.size() # 1, 3, 32, 32
__call__
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
yuv
|
(Tensor, Tensor, Tensor)
|
420 input frames in (Nx1xHxW) format |
required |
Returns:
| Type | Description |
|---|---|
Tensor or (Tensor, Tensor, Tensor)
|
Converted 444 |