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: .
This module supports TensorFloat32.
- Parameters:
- Shape:
Input: where means any number of additional dimensions and if channel_dim = 2. If channel_dim = -1, the order of input dimensions is .
Output: where all but the last dimension are the same shape as the input and if channel_dim = 2. If channel_dim = -1, the order of input dimensions is .
- Variables:
weight (torch.Tensor) – the learnable weights of the module of shape . The values are initialized from , where
bias – the learnable bias of the module of shape . If
bias
isTrue
, the values are initialized from where
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])