mmagic.models.archs.linear_module
¶
Module Contents¶
Classes¶
A linear block that contains linear/norm/activation layers. |
- class mmagic.models.archs.linear_module.LinearModule(in_features: int, out_features: int, bias: bool = True, act_cfg: Optional[dict] = dict(type='ReLU'), inplace: bool = True, with_spectral_norm: bool = False, order: Tuple[str, str] = ('linear', 'act'))[source]¶
Bases:
torch.nn.Module
A linear block that contains linear/norm/activation layers.
For low level vision, we add spectral norm and padding layer.
- Parameters
in_features (int) – Same as nn.Linear.
out_features (int) – Same as nn.Linear.
bias (bool) – Same as nn.Linear. Default: True.
act_cfg (dict) – Config dict for activation layer, “relu” by default.
inplace (bool) – Whether to use inplace mode for activation. Default: True.
with_spectral_norm (bool) – Whether use spectral norm in linear module. Default: False.
order (tuple[str]) – The order of linear/activation layers. It is a sequence of “linear”, “norm” and “act”. Examples are (“linear”, “act”) and (“act”, “linear”).
- forward(x: torch.Tensor, activate: Optional[bool] = True) torch.Tensor [source]¶
Forward Function.
- Parameters
x (torch.Tensor) – Input tensor with shape of \((n, *, c)\). Same as
torch.nn.Linear
.activate (bool, optional) – Whether to use activation layer. Defaults to True.
- Returns
Same as
torch.nn.Linear
.- Return type
torch.Tensor