設定¶
設定クラスを提供します。
MLPConfig¶
MLPConfig
dataclass
¶
Multi-layer perceptron configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
hidden_dim |
int
|
Number of hidden units. |
n_layers |
int
|
Number of layers. |
output_activation |
str
|
Activation function for output layer. |
linear_cfg |
LinearConfig
|
Linear layer configuration. |
LinearConfig¶
LinearConfig
dataclass
¶
A linear layer configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
activation |
str
|
Activation function. |
norm |
Literal['layer', 'rms', 'none']
|
Normalization layer. If it's set to "none", normalization is not applied. Default is "none". |
norm_cfg |
dict
|
Normalization layer configuration. Default is {}. |
dropout |
float
|
Dropout rate. If it's set to 0.0, dropout is not applied. Default is 0.0. |
norm_first |
bool
|
Whether to apply normalization before linear layer. Default is False. |
bias |
bool
|
Whether to use bias. Default is True. |
ConvConfig¶
ConvConfig
dataclass
¶
ConvConfig(activation, kernel_size, stride, padding, output_padding=0, dilation=1, groups=1, bias=True, padding_mode='zeros', dropout=0.0, norm='none', norm_cfg=dict(), norm_first=False, scale_factor=0)
A convolutional layer configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
activation |
str
|
Activation function. |
kernel_size |
int
|
Kernel size. |
stride |
int
|
Stride. |
padding |
int
|
Padding. |
output_padding |
int
|
Output padding, especially for transposed convolution. Default is 0. |
dilation |
int
|
Dilation. |
groups |
int
|
Number of groups. Default is 1. See https://pytorch.org/docs/stable/generated/torch.nn.Conv2d.html. |
bias |
bool
|
Whether to use bias. Default is True. |
dropout |
float
|
Dropout rate. If it's set to 0.0, dropout is not applied. Default is 0.0. |
norm |
Literal['batch', 'group', 'none']
|
Normalization layer. If it's set to "none", normalization is not applied. Default is "none". |
norm_cfg |
dict
|
Normalization layer configuration. If you want to use Instance, Layer, or Group normalization, set norm to "group" and set norm_cfg with "num_groups=$in_channel, 1, or any value". Default is {}. |
scale_factor |
int
|
Scale factor for upsample, especially for PixelShuffle or PixelUnshuffle. If it's set to >0, upsample is applied. If it's set to <0 downsample is applied. Otherwise, no upsample or downsample is applied. Default is 0. |
ConvNetConfig¶
ConvNetConfig
dataclass
¶
Convolutional neural network layers configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
channels |
Tuple[int, ...]
|
Number of channels for each layer. |
conv_cfgs |
Tuple[ConvConfig, ...]
|
Convolutional layer configurations. The length of conv_cfgs should be the same as the length of channels. |
init_channel |
int
|
Initial number of channels, especially for transposed convolution. |
Attributes¶
Functions¶
__post_init__ ¶
dictcfg2dict ¶
Convert dictConfig to dict for ConvNetConfig.
Source code in src/ml_networks/config.py
ResNetConfig¶
ResNetConfig
dataclass
¶
ResNetConfig(conv_channel, conv_kernel, f_kernel, conv_activation, out_activation, n_res_blocks, scale_factor=2, n_scaling=2, norm='none', norm_cfg=dict(), dropout=0.0, init_channel=16, padding_mode='zeros', attention=None)
Residual neural network layers configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
conv_channel |
int
|
Number of channels for convolutional layer. In ResNet, common number of channels is used for all layers. |
conv_kernel |
int
|
Kernel size for convolutional layer. In ResNet, common kernel size is used for all layers. |
f_kernel |
int
|
Kernel size for final or first convolutional layer. This depends on whether PixelShuffle or PixelUnshuffle is used. |
conv_activation |
str
|
Activation function for convolutional layer. |
out_activation |
str
|
Activation function for output layer. |
n_res_blocks |
int
|
Number of residual blocks. |
scale_factor |
int
|
Scale factor for upsample, especially for PixelShuffle or PixelUnshuffle. |
n_scaling |
int
|
Number of upsample or downsample layers. The image size is scaled by scalefactor^n_scaling. |
norm |
Literal['batch', 'group', 'none']
|
Normalization layer. If it's set to "none", normalization is not applied. Default is "none". |
norm_cfg |
dict
|
Normalization layer configuration. If you want to use Instance, Layer, or Group normalization, set norm to "group" and set norm_cfg with "num_groups=$in_channel, 1, or any value". Default is {}. |
dropout |
float
|
Dropout rate. If it's set to 0.0, dropout is not applied. Default is 0.0. |
init_channel |
int
|
Initial number of channels, especially for decoder. |
EncoderConfig¶
EncoderConfig
dataclass
¶
Encoder configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
backbone |
Union[ConvNetConfig, ResNetConfig]
|
Backbone configuration. |
full_connection |
Union[MLPConfig, LinearConfig, SpatialSoftmaxConfig]
|
Full connection configuration. |
Attributes¶
Functions¶
dictcfg2dict ¶
Convert dictConfig to dict for EncoderConfig.
Source code in src/ml_networks/config.py
DecoderConfig¶
DecoderConfig
dataclass
¶
Decoder configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
backbone |
Union[ConvNetConfig, ResNetConfig]
|
Backbone configuration. |
full_connection |
Union[MLPConfig, LinearConfig, SpatialSoftmaxConfig]
|
Full connection configuration. |
Attributes¶
Functions¶
dictcfg2dict ¶
Convert dictConfig to dict for DecoderConfig.
Source code in src/ml_networks/config.py
ViTConfig¶
ViTConfig
dataclass
¶
Vision Transformer configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
patch_size |
int
|
Patch size. |
transformer_cfg |
TransformerConfig
|
Transformer configuration. |
cls_token |
bool
|
Whether to use class token. Default is True. |
init_channel |
int
|
Initial number of channels. Default is 16. |
UNetConfig¶
UNetConfig
dataclass
¶
UNetConfig(channels, conv_cfg, cond_pred_scale=False, nhead=None, has_attn=False, use_shuffle=False, use_hypernet=False, hyper_mlp_cfg=None)
UNet configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
channels |
Tuple[int, ...]
|
Number of channels for each layer. |
conv_cfg |
ConvConfig
|
Convolutional layer configuration. |
cond_cfg |
MLPConfig
|
Conditional configuration for UNet. |
cond_pred_scale |
bool
|
Whether to scale the conditional prediction. Default is False. |
nhead |
Optional[int]
|
Number of heads for attention mechanism. If it's set to None, attention is not applied. Default is None. |
has_attn |
bool
|
Whether to use attention mechanism. Default is False. |
use_shuffle |
bool
|
Whether to use PixelShuffle or PixelUnshuffle. Default is False. |
use_hypernet |
bool
|
Whether to use hypernetwork. Default is False. |
hyper_mlp_cfg |
Optional[MLPConfig]
|
Hypernetwork configuration. If it's set to None, hypernetwork is not used. Default is None. |
SpatialSoftmaxConfig¶
SpatialSoftmaxConfig
dataclass
¶
SpatialSoftmaxConfig(temperature=1.0, eps=1e-06, is_argmax=False, is_straight_through=False, additional_layer=None)
Spatial softmax configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
temperature |
float
|
Softmax temperature. If it's set to 0.0, the layer outputs the coordinates of the maximum value. Otherwise, the layer outputs the expectation of the coordinates with softmax function. Default is 0.0. |
eps |
float
|
Epsilon value for numerical stability in softmax. Default is 1e-6. |
is_argmax |
bool
|
Whether to use argmax instead of softmax. Default is False. |
is_straight_through |
bool
|
Whether to use straight-through estimator for backpropagation. Default is False. |
additional_layer |
Optional[Union[MLPConfig, LinearConfig]]
|
Additional layer configuration. If it's set to None, no additional layer is applied. Default is None. |
AttentionConfig¶
AttentionConfig
dataclass
¶
TransformerConfig¶
TransformerConfig
dataclass
¶
TransformerConfig(d_model, nhead, dim_ff, n_layers, dropout=0.1, hidden_activation='GELU', output_activation='GeLU')
Transformer configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
d_model |
int
|
Dimension of model. |
nhead |
int
|
Number of heads. |
dim_ff |
int
|
Dimension of feedforward network. |
n_layers |
int
|
Number of layers. |
dropout |
float
|
Dropout rate. Default is 0.1. |
hidden_activation |
Literal['ReLU', 'GELU']
|
Activation function for hidden layer. Default is "GELU". |
output_activation |
str
|
Activation function for output layer. Default is "GeLU". |
AdaptiveAveragePoolingConfig¶
AdaptiveAveragePoolingConfig
dataclass
¶
Adaptive average pooling configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
output_size |
Union[int, Tuple[int, ...]]
|
Output size of the pooling layer. If it's an integer, it will be used for both height and width. If it's a tuple, it should contain two integers for height and width. |