Shortcuts

Linear

class continual.Linear(in_features, out_features, bias=True, device=None, dtype=None, channel_dim=- 1)[source]

Applies a linear transformation to a dimension of the incoming data: y=xAT+by = xA^T + b.

This module supports TensorFloat32.

Parameters:
  • in_features (int) – size of each input sample

  • out_features (int) – size of each output sample

  • bias (bool) – If set to False, the layer will not learn an additive bias. Default: True

  • channel_dim – Channel dimension index over which to perform linear projection. Default: -1.

Shape:
  • Input: (B,Cin,T,)(B, C_{in}, T, *) where * means any number of additional dimensions and Cin=in_featuresC_{in} = \text{in\_features} if channel_dim = 2. If channel_dim = -1, the order of input dimensions is (,Cin)(*, C_{in}).

  • Output: (B,Cout,T,)(B, C_{out}, T, *) where all but the last dimension are the same shape as the input and Cout=out_featuresC_{out} = \text{out\_features} if channel_dim = 2. If channel_dim = -1, the order of input dimensions is (,Cin)(*, C_{in}).

Variables:
  • weight (torch.Tensor) – the learnable weights of the module of shape (out_features,in_features)(\text{out\_features}, \text{in\_features}). The values are initialized from U(k,k)\mathcal{U}(-\sqrt{k}, \sqrt{k}), where k=1in_featuresk = \frac{1}{\text{in\_features}}

  • bias – the learnable bias of the module of shape (out_features)(\text{out\_features}). If bias is True, the values are initialized from U(k,k)\mathcal{U}(-\sqrt{k}, \sqrt{k}) where k=1in_featuresk = \frac{1}{\text{in\_features}}

Examples:

# Use like torch.nn.Linear
m = co.Linear(20, 30)
input = torch.randn(128, 20)
output = m(input)
assert output.size() == torch.Size([128, 30])

# Or in conjunction with other continual modules
#                   B  C  T   H    W
input = torch.randn(1, 3, 16, 128, 128)
net = co.Sequential(
    co.Conv3d(3, 32, 3),
    co.AdaptiveAvgPool3d((1, 1, 1), 32),
    co.Linear(32, 10, channel_dim=1),
)
output = net(input)
assert output.size() == torch.Size([1, 10, 1, 1, 1])
Read the Docs v: latest
Versions
latest
stable
Downloads
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.