AddCoords
AddCoords
Bases: Module
AddCoords is a PyTorch module that adds additional channels to the input tensor containing the relative
(normalized to [-1, 1]
) coordinates of each input element along the specified number of dimensions (rank
).
Essentially, it adds spatial context information to the tensor.
Typically, these inputs are feature maps coming from some CNN, where the spatial organization of the input matters (such as an image or speech signal).
This additional spatial context allows subsequent layers (such as convolutions) to learn position-dependent features. For example, in tasks where the absolute position of features matters (such as denoising and segmentation tasks), it helps the model to know where (in terms of relative position) the features are.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rank |
int
|
The dimensionality of the input tensor. That is to say, this tells us how many dimensions the input tensor's spatial context has. It's assumed to be 1, 2, or 3 corresponding to some 1D, 2D, or 3D data (like an image). |
required |
with_r |
bool
|
Boolean indicating whether to add an extra radial distance channel or not. If True, an extra channel is appended, which measures the Euclidean (L2) distance from the center of the image. This might be useful when the proximity to the center of the image is important to the task. |
False
|
Source code in models/tts/delightful_tts/conv_blocks/add_coords.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|
forward(x)
Forward pass of the AddCoords module. Depending on the rank of the tensor, it adds one or more new channels
with relative coordinate values. If with_r
is True, an extra radial channel is included.
For example, for an image (rank=2
), two channels would be added which contain the normalized x and y
coordinates respectively of each pixel.
Calling the forward method updates the original tensor x
with the added channels.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
Tensor
|
The input tensor. |
required |
Returns:
Name | Type | Description |
---|---|---|
out |
Tensor
|
The input tensor with added coordinate and possibly radial channels. |
Source code in models/tts/delightful_tts/conv_blocks/add_coords.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
|