caveat.models.utils
ScheduledOptim(optimizer, lr_mul, d_model, n_warmup_steps)
#
Bases: _LRScheduler
A simple wrapper class for learning rate scheduling
Source code in caveat/models/utils.py
build_hidden_layers(config)
#
Build hidden layer sizes from config.
PARAMETER | DESCRIPTION |
---|---|
config
|
Configuration dictionary containing hidden layer parameters.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
ValueError
|
If both hidden_layers and hidden_n/hidden_size are specified. |
ValueError
|
If hidden_layers is not a list. |
ValueError
|
If hidden_layers contains non-integer values. |
ValueError
|
If neither hidden_layers nor hidden_n/hidden_size are specified. |
RETURNS | DESCRIPTION |
---|---|
list
|
List of hidden layer sizes.
TYPE:
|
Source code in caveat/models/utils.py
calc_output_padding_1d(length, target, kernel_size, stride, padding, patience=20)
#
Calculate the output padding required for a 1D transposed convolution to achieve a target length. This function iterates over possible padding values and output padding values to find a combination that results in the desired target length after a 1D transposed convolution. Args: length (int): The length of the input. target (int): The desired length of the output. kernel_size (int): The size of the convolution kernel. stride (int): The stride of the convolution. padding (int): The initial padding value. patience (int, optional): The maximum number of iterations to try for padding and output padding. Default is 20. Returns: tuple: A tuple containing the padding and output padding values that achieve the target length. Raises: ValueError: If no combination of padding and output padding can achieve the target length within the given patience.
Source code in caveat/models/utils.py
calc_output_padding_2d(size)
#
Calculate output padding for a transposed convolution such that output dims will match dimensions of inputs to a convolution of given size. For each dimension, padding is set to 1 if even size, otherwise 0.
PARAMETER | DESCRIPTION |
---|---|
size
|
input size (h, w) |
RETURNS | DESCRIPTION |
---|---|
array
|
np.array: required padding |
Source code in caveat/models/utils.py
conv1d_size(length, kernel_size, stride, padding=0)
#
Calculate output dimensions for 1d convolution.
PARAMETER | DESCRIPTION |
---|---|
length
|
Input size.
TYPE:
|
kernel_size
|
Kernel_size.
TYPE:
|
stride
|
Stride.
TYPE:
|
padding
|
Input padding.
TYPE:
|
Returns: int: Output size.
Source code in caveat/models/utils.py
conv2d_size(size, kernel_size=3, stride=2, padding=1, dilation=1)
#
Calculate output dimensions for 2d convolution.
PARAMETER | DESCRIPTION |
---|---|
size
|
Input size, may be integer if symetric. |
kernel_size
|
Kernel_size. Defaults to 3. |
stride
|
Stride. Defaults to 2. |
padding
|
Input padding. Defaults to 1. |
dilation
|
Dilation. Defaults to 1. |
RETURNS | DESCRIPTION |
---|---|
array
|
np.array: Output size. |
Source code in caveat/models/utils.py
duration_mask(mask)
#
hot_argmax(batch, axis=-1)
#
Encoded given axis as one-hot based on argmax for that axis.
PARAMETER | DESCRIPTION |
---|---|
batch
|
Input tensor.
TYPE:
|
axis
|
Axis index to encode. Defaults to -1.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
tensor
|
One hot encoded tensor.
TYPE:
|
Source code in caveat/models/utils.py
transconv_size_1d(length, kernel_size, stride, padding, output_padding, dilation=1)
#
transconv_size_2d(size, kernel_size=3, stride=2, padding=1, dilation=1, output_padding=1)
#
Calculate output dimension for 2d transpose convolution.
PARAMETER | DESCRIPTION |
---|---|
size
|
Input size, may be integer if symetric. |
kernel_size
|
Kernel size. Defaults to 3. |
stride
|
Stride. Defaults to 2. |
padding
|
Input padding. Defaults to 1. |
dilation
|
Dilation. Defaults to 1. |
output_padding
|
Output padding. Defaults to 1. |
RETURNS | DESCRIPTION |
---|---|
array
|
np.array: Output size. |