cassetta.layers
Overview
Layers are relatively simple modules or sequences of modules. They should be used as basic blocks for building backbones.
| MODULE | DESCRIPTION |
|---|---|
activations |
Activation functions |
attention |
Attention layers (squeeze & excite, dot-product, multi-head, ...) |
conv |
Basic N-dimensional convolution layers |
convblocks |
Building blocks for convolutional networks |
dropout |
N-dimensional dropout layers |
interpol |
N-dimensional interpolation and grid sampling |
linear |
Linear layer (slightly more practical than PyTorch's) |
simple |
A bunch of embarassingly simple layers (Cat, Sum, ...) |
updown |
Different ways to upsample and downsample |
cassetta.layers.activations
SymExp
SymLog
make_activation
Instantiate an activation module.
To be accepted in a nn.Sequential module or in a nn.ModuleList,
an activation must be a nn.Module. This function takes other
forms of "activation parameters" that are typically passed to the
constructor of larger models, and generate the corresponding
instantiated Module.
An activation-like can be a nn.Module subclass, which is
then instantiated, or a callable function that returns an
instantiated Module.
It is useful to accept both these cases as they allow to either:
- have a learnable activation specific to this module
- have a learnable activation shared with other modules
- have a non-learnable activation
| PARAMETER | DESCRIPTION |
|---|---|
activation |
An already instantiated
TYPE:
|
kwargs |
Additional parameters to pass to the constructor or function.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
activation
|
An instantiated
TYPE:
|
Source code in cassetta/layers/activations.py
cassetta.layers.attention
ChannelSqzEx
Bases: Sequential
Spatial Squeeze & Channel Excitation layer
Diagram
flowchart LR
subgraph Spatial Squeeze
1["`[C, W]`"] ---2("`MeanPool`"):::d--> 3["`[C, 1]`"]
end
subgraph MLP
4("`Linear`"):::w -->
5["`[C//r, 1]`"] ---6("`ReLU`"):::d -->
7["`[C//r, 1]`"] ---8("`Linear`"):::w
end
subgraph Channel Excitation
9["`[C, 1]`"] ---10("`Sigmoid`"):::d -->
11["`[C, 1]`"] ---12(("*")):::d -->
13["`[C, W]`"]
end
3 --- 4
8 --> 9
1 --> 12
classDef d fill:lightcyan,stroke:lightblue;
classDef w fill:papayawhip,stroke:peachpuff;
Note that the batch dimension is not represented, but must
be present.
Reference
-
Hu, J, et al. "Squeeze-and-Excitation Networks." CVPR (2018), TPAMI (2019). arxiv:1709.01507
-
Roy, AG, et al. "Concurrent Spatial and Channel Squeeze & Excitation in Fully Convolutional Networks" MICCAI (2018). arxiv:1803.02579
| PARAMETER | DESCRIPTION |
|---|---|
channels |
Number of input and output channels
TYPE:
|
compression |
Compression ratio for the number of channels in the squeeze
TYPE:
|
activation |
Activation function
TYPE:
|
Source code in cassetta/layers/attention.py
SpatialSqzEx
Bases: Sequential
Channel Squeeze & Spatial Excitation layer
Diagram
flowchart LR
subgraph Channel Squeeze
1["`[C, W]`"] ---2("`Linear`"):::w--> 3["`[1, W]`"]
end
subgraph Spatial Excitation
4("`Sigmoid`"):::d--> 5["`[1, W]`"] ---6(("*")):::d-->7["`[C, W]`"]
end
3 --- 4
1 --> 6
classDef d fill:lightcyan,stroke:lightblue;
classDef w fill:papayawhip,stroke:peachpuff;
Note that the batch dimension is not represented, but must
be present.
Reference
- Roy, AG, et al. "Concurrent Spatial and Channel Squeeze & Excitation in Fully Convolutional Networks" MICCAI (2018). arxiv:1803.02579
| PARAMETER | DESCRIPTION |
|---|---|
channels |
Number of input and output channels
TYPE:
|
Source code in cassetta/layers/attention.py
forward
| PARAMETER | DESCRIPTION |
|---|---|
inp |
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
out
|
TYPE:
|
SqzEx
SqzEx(channels, mode='+', compression=16, activation='ReLU', device=None, dtype=None, **unused_kwargs)
Bases: Sequential
Concurrent Spatial and Channel Squeeze & Spatial Excitation layer
Diagram
flowchart LR
6(("+")):::d --> 7["`[C, W]`"]
1["`[C, W]`"] ---2("Channel Squeeze & Excite"):::w-->
3["`[C, W]`"]
1 ---4("Spatial Squeeze & Excite"):::w-->
5["`[C, W]`"]
3 --- 6
5 --> 6
classDef d fill:lightcyan,stroke:lightblue;
classDef w fill:papayawhip,stroke:peachpuff;
flowchart LR
1["`[C, W]`"] ---2("Channel Squeeze & Excite"):::w-->
3["`[C, W]`"] ---4("Spatial Squeeze & Excite"):::w-->
5["`[C, W]`"]
classDef d fill:lightcyan,stroke:lightblue;
classDef w fill:papayawhip,stroke:peachpuff;
flowchart LR
1["`[C, W]`"] ---2("Spatial Squeeze & Excite"):::w-->
3["`[C, W]`"] ---4("Channel Squeeze & Excite"):::w-->
5["`[C, W]`"]
classDef d fill:lightcyan,stroke:lightblue;
classDef w fill:papayawhip,stroke:peachpuff;
Note that the batch dimension is not represented, but must be present.
Reference
- Roy, AG, et al. "Concurrent Spatial and Channel Squeeze & Excitation in Fully Convolutional Networks" MICCAI (2018). arxiv:1803.02579
| PARAMETER | DESCRIPTION |
|---|---|
ndim |
Number of spatial dimensions
TYPE:
|
channels |
Number of input and output channels
TYPE:
|
mode |
Squeeze and excitation mode:
TYPE:
|
compression |
Compression ratio for the number of channels in the squeeze
TYPE:
|
activation |
Activation function
TYPE:
|
Source code in cassetta/layers/attention.py
forward
| PARAMETER | DESCRIPTION |
|---|---|
inp |
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
out
|
TYPE:
|
Source code in cassetta/layers/attention.py
ChannelBlockAttention
ChannelBlockAttention(channels, compression=16, activation='ReLU', device=None, dtype=None, **unused_kwargs)
Bases: Sequential
Channel Attention for Convolutional Block Attention Module
Diagram
flowchart LR
subgraph Spatial Squeeze
1["`[C, W]`"] ---2("`MeanPool`"):::d--> 3["`[C, 1]`"]
1 ---4("`MaxPool`"):::d--> 5["`[C, 1]`"]
end
subgraph MLP - shared weights
6("`Linear`"):::w -->
7["`[C//r, 1]`"] ---8("`ReLU`"):::d -->
9["`[C//r, 1]`"] ---10("`Linear`"):::w
end
subgraph MLP - shared weights
11("`Linear`"):::w -->
12["`[C//r, 1]`"] ---13("`ReLU`"):::d -->
14["`[C//r, 1]`"] ---15("`Linear`"):::w
end
subgraph Channel Attention
20("`Sigmoid`"):::d -->
21["`[C, 1]`"] --- 22(("*")):::d --> 23["`[C, W]`"]
end
16["`[C, 1]`"] & 17["`[C, 1]`"] ---18(("+")):::d--> 19["`[C, 1]`"]
3 --- 6
5 --- 11
10 --> 16
15 --> 17
19 --- 20
1 --> 22
classDef d fill:lightcyan,stroke:lightblue;
classDef w fill:papayawhip,stroke:peachpuff;
Note that the batch dimension is not represented, but must
be present.
Reference
- Woo, S, et al. "CBAM: Convolutional Block Attention Module." ECCV (2018). arxiv:1807.06521
| PARAMETER | DESCRIPTION |
|---|---|
channels |
Number of input and output channels
TYPE:
|
compression |
Compression ratio for the number of channels in the squeeze
TYPE:
|
activation |
Activation function
TYPE:
|
Source code in cassetta/layers/attention.py
forward
| PARAMETER | DESCRIPTION |
|---|---|
inp |
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
out
|
TYPE:
|
Source code in cassetta/layers/attention.py
SpatialBlockAttention
Bases: Sequential
Spatial Attention for Convolutional Block Attention Module
Diagram
flowchart LR
subgraph Channel Squeeze
1["`[C, W]`"] ---2("`ChannelMean`"):::d--> 3["`[1, W]`"]
1 ---4("`ChannelMax`"):::d--> 5["`[1, W]`"]
end
3 & 5 ---6(("c")):::d--> 7["`[2, W]`"]
7 ---8("`Conv 7`"):::w--> 9["`[1, W]`"]
subgraph Spatial Excitation
10("`Sigmoid`"):::d--> 11["`[1, W]`"] ---12(("*")):::d-->
13["`[C, W]`"]
end
9 --> 10
1 --> 12
classDef d fill:lightcyan,stroke:lightblue;
classDef w fill:papayawhip,stroke:peachpuff;
Note that the batch dimension is not represented, but must
be present.
Reference
- Woo, S, et al. "CBAM: Convolutional Block Attention Module." ECCV (2018). arxiv:1807.06521
| PARAMETER | DESCRIPTION |
|---|---|
ndim |
Number of spatial dim
TYPE:
|
kernel_size |
Kernel size of the convolution layer
TYPE:
|
Source code in cassetta/layers/attention.py
forward
| PARAMETER | DESCRIPTION |
|---|---|
inp |
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
out
|
TYPE:
|
Source code in cassetta/layers/attention.py
BlockAttention
BlockAttention(ndim, channels, mode='cs', compression=16, activation='ReLU', kernel_size=7, **unused_kwargs)
Bases: Sequential
Channel + Spatial Attention layer
Diagram
flowchart LR
6(("+")):::d --> 7["`[C, W]`"]
1["`[C, W]`"] ---2("Channel Attention"):::w--> 3["`[C, W]`"]
1 ---4("Spatial Attention"):::w--> 5["`[C, W]`"]
3 --- 6
5 --> 6
classDef d fill:lightcyan,stroke:lightblue;
classDef w fill:papayawhip,stroke:peachpuff;
flowchart LR
1["`[C, W]`"] ---2("Channel Attention"):::w-->
3["`[C, W]`"] ---4("Spatial Attention"):::w-->
5["`[C, W]`"]
classDef d fill:lightcyan,stroke:lightblue;
classDef w fill:papayawhip,stroke:peachpuff;
flowchart LR
1["`[C, W]`"] ---2("Spatial Attention"):::w-->
3["`[C, W]`"] ---4("Channel Attention"):::w-->
5["`[C, W]`"]
classDef d fill:lightcyan,stroke:lightblue;
classDef w fill:papayawhip,stroke:peachpuff;
Note that the batch dimension is not represented, but must be present.
Reference
- Woo, Sanghyun, et al. "CBAM: Convolutional Block Attention Module." ECCV (2018). https://arxiv.org/abs/1807.06521v2
| PARAMETER | DESCRIPTION |
|---|---|
ndim |
Number of spatial dim
TYPE:
|
channels |
Number of input and output channels
TYPE:
|
mode |
Attention mode:
TYPE:
|
compression |
Compression ratio for the number of channels in the squeeze
TYPE:
|
activation |
Activation function
TYPE:
|
kernel_size |
Kernel size of the convolution layer
TYPE:
|
Source code in cassetta/layers/attention.py
forward
| PARAMETER | DESCRIPTION |
|---|---|
inp |
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
out
|
TYPE:
|
Source code in cassetta/layers/attention.py
DotProductAttention
Bases: Module
Under construction -- do not use
References
- Vaswani, Ashish, et al. **"Attention Is All You Need." NeurIPS (2017). https://arxiv.org/abs/1706.03762v7
| PARAMETER | DESCRIPTION |
|---|---|
key_channels |
Number of keys
TYPE:
|
val_channels |
Number of values
TYPE:
|
scaled |
Scale the dot product
TYPE:
|
Source code in cassetta/layers/attention.py
forward
| PARAMETER | DESCRIPTION |
|---|---|
inp |
Input tensor
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
out
|
TYPE:
|
Source code in cassetta/layers/attention.py
MultiHeadAttention
MultiHeadAttention(inp_channels, key_channels, val_channels, nb_heads, scaled=True, **unused_kwargs)
Bases: Module
Under construction -- do not use
References
- Vaswani, Ashish, et al. **"Attention Is All You Need." NeurIPS (2017). https://arxiv.org/abs/1706.03762v7
| PARAMETER | DESCRIPTION |
|---|---|
inp_channels |
Number of input channels
TYPE:
|
key_channels |
Number of keys
TYPE:
|
val_channels |
Number of values
TYPE:
|
nb_heads |
Number of heads
TYPE:
|
scaled |
Scale the dot product
TYPE:
|
Source code in cassetta/layers/attention.py
forward
| PARAMETER | DESCRIPTION |
|---|---|
inp |
Input tensor
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
out
|
TYPE:
|
Source code in cassetta/layers/attention.py
make_attention
Instantiate an attention layer
| PARAMETER | DESCRIPTION |
|---|---|
attention |
An already instantiated
TYPE:
|
channels |
Number of channels
TYPE:
|
ndim |
Number of spatial dimensions
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
attention
|
An attention layer
TYPE:
|
Source code in cassetta/layers/attention.py
cassetta.layers.conv
Conv
Conv(ndim, inp_channels, out_channels=None, kernel_size=3, stride=1, padding=0, dilation=1, output_padding=0, groups=1, bias=True, padding_mode='zeros', device=None, dtype=None)
Bases: _Conv
| PARAMETER | DESCRIPTION |
|---|---|
ndim |
Number of spatial dimensions
TYPE:
|
inp_channels |
Number of input channels
TYPE:
|
out_channels |
Number of output channels
TYPE:
|
kernel_size |
Kernel size
TYPE:
|
stride |
Space between output elements
TYPE:
|
padding |
Amount of padding to apply
TYPE:
|
dilation |
Space between kernel elements
TYPE:
|
output_padding |
Amount of padding to apply to the ouptput of a transposed convolution.
TYPE:
|
groups |
Number of groups
TYPE:
|
bias |
Add a learnable bias term
TYPE:
|
padding_mode |
How to pad the tensor
TYPE:
|
Source code in cassetta/layers/conv.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
forward
| PARAMETER | DESCRIPTION |
|---|---|
inp |
Input tensor
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
out
|
Convolved tensor
TYPE:
|
Source code in cassetta/layers/conv.py
ConvTransposed
ConvTransposed(ndim, inp_channels, out_channels=None, kernel_size=3, stride=1, padding=0, dilation=1, output_padding=0, groups=1, bias=True, padding_mode='zeros', device=None, dtype=None)
Bases: _Conv
| PARAMETER | DESCRIPTION |
|---|---|
ndim |
Number of spatial dimensions
TYPE:
|
inp_channels |
Number of input channels
TYPE:
|
out_channels |
Number of output channels
TYPE:
|
kernel_size |
Kernel size
TYPE:
|
stride |
Space between output elements
TYPE:
|
padding |
Amount of padding to apply
TYPE:
|
dilation |
Space between kernel elements
TYPE:
|
output_padding |
Amount of padding to apply to the ouptput of a transposed convolution.
TYPE:
|
groups |
Number of groups
TYPE:
|
bias |
Add a learnable bias term
TYPE:
|
padding_mode |
How to pad the tensor
TYPE:
|
Source code in cassetta/layers/conv.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
forward
| PARAMETER | DESCRIPTION |
|---|---|
inp |
Input tensor
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
out
|
Output tensor
TYPE:
|
Source code in cassetta/layers/conv.py
LazyConv
LazyConv(out_channels=None, kernel_size=3, stride=1, padding=0, dilation=1, output_padding=0, groups=1, bias=True, padding_mode='zeros', device=None, dtype=None)
Bases: LazyModuleMixin, Conv
A convolution layer whose ndim and inp_channels are guessed
lazily at run time.
| PARAMETER | DESCRIPTION |
|---|---|
out_channels |
Number of output channels. If a function, takes the materialized number of input channels and return the materialized number of output channels.
TYPE:
|
kernel_size |
Kernel size
TYPE:
|
stride |
Space between output elements
TYPE:
|
padding |
Amount of padding to apply
TYPE:
|
dilation |
Space between kernel elements
TYPE:
|
groups |
Number of groups
TYPE:
|
bias |
Add a learnable bias term
TYPE:
|
padding_mode |
How to pad the tensor
TYPE:
|
Source code in cassetta/layers/conv.py
LazyConvTransposed
LazyConvTransposed(out_channels=None, kernel_size=3, stride=1, padding=0, dilation=1, output_padding=0, groups=1, bias=True, padding_mode='zeros', device=None, dtype=None)
Bases: LazyModuleMixin, Conv
A transposed convolution layer whose ndim and inp_channels are
guessed lazily at run time.
| PARAMETER | DESCRIPTION |
|---|---|
out_channels |
Number of output channels. If a function, takes the materialized number of input channels and return the materialized number of output channels.
TYPE:
|
kernel_size |
Kernel size
TYPE:
|
stride |
Space between output elements
TYPE:
|
padding |
Amount of padding to apply
TYPE:
|
dilation |
Space between kernel elements
TYPE:
|
output_padding |
Amount of padding to apply to the ouptput of a transposed convolution.
TYPE:
|
groups |
Number of groups
TYPE:
|
bias |
Add a learnable bias term
TYPE:
|
padding_mode |
How to pad the tensor
TYPE:
|
Source code in cassetta/layers/conv.py
SeparableConv
SeparableConv(ndim, inp_channels, out_channels=None, kernel_size=3, dilation=1, bias=True, padding='same', padding_mode='zeros')
Bases: Sequential
Separable Convolution.
Implements a ND convolution (e.g., WxHxD) as a series of 1D convolutions (e.g., Wx1x1, 1xHx1, 1x1xD).
The number of input and output channels will be the same
Padding mode is 'same' by default
| PARAMETER | DESCRIPTION |
|---|---|
ndim |
Number of spatial dimensions
TYPE:
|
inp_channels |
Number of input channels
TYPE:
|
out_channels |
Number of output channels
TYPE:
|
kernel_size |
Kernel size
TYPE:
|
dilation |
Space between kernel elements
TYPE:
|
bias |
Add a learnable bias term
TYPE:
|
padding |
Amount of padding to apply
TYPE:
|
padding_mode |
How to pad the tensor
TYPE:
|
Source code in cassetta/layers/conv.py
CrossHairConv
CrossHairConv(ndim, inp_channels, out_channels=None, kernel_size=3, dilation=1, bias=True, padding='same', padding_mode='zeros')
Bases: SeparableConv
Separable Cross-Hair Convolution.
Separable convolution, where the input tensor is convolved with a set of 1D convolutions, and all outputs are summed together (e.g., Wx1x1 + 1xHx1 + 1x1xD).
Padding must be 'same'
Reference
Tetteh, Giles, et al. "Deepvesselnet: Vessel segmentation, centerline prediction, and bifurcation detection in 3-d angiographic volumes." Frontiers in Neuroscience 14 (2020). 10.3389/fnins.2020.592352
bibtex
@article{tetteh2020deepvesselnet,
title={Deepvesselnet: Vessel segmentation, centerline prediction, and bifurcation detection in 3-d angiographic volumes},
author={Tetteh, Giles and Efremov, Velizar and Forkert, Nils D and Schneider, Matthias and Kirschke, Jan and Weber, Bruno and Zimmer, Claus and Piraud, Marie and Menze, Bj{"o}rn H},
journal={Frontiers in Neuroscience},
volume={14},
pages={592352},
year={2020},
publisher={Frontiers}
}
| PARAMETER | DESCRIPTION |
|---|---|
ndim |
Number of spatial dimensions
TYPE:
|
inp_channels |
Number of input channels
TYPE:
|
out_channels |
Number of output channels
TYPE:
|
kernel_size |
Kernel size
TYPE:
|
dilation |
Space between kernel elements
TYPE:
|
bias |
Add a learnable bias term
TYPE:
|
padding |
Amount of padding to apply
TYPE:
|
padding_mode |
How to pad the tensor
TYPE:
|
Source code in cassetta/layers/conv.py
forward
| PARAMETER | DESCRIPTION |
|---|---|
inp |
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
out
|
TYPE:
|
Source code in cassetta/layers/conv.py
make_conv
make_conv(ndim, inp_channels, out_channels=None, kernel_size=3, stride=1, padding=0, dilation=1, output_padding=0, groups=1, bias=True, separable=False, transpose=False, padding_mode='zeros', device=None, dtype=None)
Instantiate a convolution layer.
| PARAMETER | DESCRIPTION |
|---|---|
ndim |
Number of spatial dimensions
TYPE:
|
inp_channels |
Number of input channels
TYPE:
|
out_channels |
Number of output channels
TYPE:
|
kernel_size |
Kernel size
TYPE:
|
stride |
Space between output elements
TYPE:
|
padding |
Amount of padding to apply
TYPE:
|
dilation |
Space between kernel elements
TYPE:
|
output_padding |
Amount of padding to apply to the ouptput of a transposed convolution.
TYPE:
|
groups |
Number of groups
TYPE:
|
bias |
Add a learnable bias term
TYPE:
|
padding_mode |
How to pad the tensor
TYPE:
|
device |
Weights' device
TYPE:
|
dtype |
Weights' data type
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
layer
|
TYPE:
|
Source code in cassetta/layers/conv.py
cassetta.layers.convblocks
ConvBlockBase
ConvBlockBase(ndim, inp_channels, out_channels=None, activation='ReLU', norm=None, dropout=None, attention=None, order='ncdax', optc=None, opta=None, optn=None, optd=None, optx=None)
Bases: Sequential
Base class for unstrided convolution blocks that contain any of these layers:
- Norm (n)
- Conv (c)
- Dropout (d)
- Activation (a)
- Attention (x)
Source code in cassetta/layers/convblocks.py
ConvBlock
ConvBlock(ndim, inp_channels, out_channels, kernel_size=3, dilation=1, bias=True, activation='ReLU', norm=None, dropout=None, attention=None, compression=16, order='ncdax', separable=False, optc=None, optn=None, optd=None, opta=None, optx=None)
Bases: ConvBlockBase
A single convolution, in a Norm + Conv + Dropout + Activation + Attention group.
Diagram
flowchart LR
subgraph ConvBlock
n("Norm"):::w-->
on["C<sub>inp</sub>"] ---c("Conv"):::w-->
oc["C<sub>out</sub>"] ---d("Dropout"):::d-->
od["C<sub>out</sub>"] ---a("Activation"):::d-->
oa["C<sub>out</sub>"] --- x("Attention"):::w
end
i["C<sub>inp</sub>"]:::i --- n
x --> ox["C<sub>out</sub>"]:::o
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef w fill:papayawhip,stroke:peachpuff;
classDef d fill:lightcyan,stroke:lightblue;
classDef n fill:none,stroke:none;
flowchart LR
subgraph ConvBlock
c("Conv"):::w-->
oc["C<sub>out</sub>"] ---n("Norm"):::w-->
on["C<sub>out</sub>"] ---d("Dropout"):::d-->
od["C<sub>out</sub>"] ---a("Activation"):::d-->
oa["C<sub>out</sub>"] --- x("Attention"):::w
end
i["C<sub>inp</sub>"]:::i --- c
x --> ox["C<sub>out</sub>"]:::o
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef w fill:papayawhip,stroke:peachpuff;
classDef d fill:lightcyan,stroke:lightblue;
classDef n fill:none,stroke:none;
Padding is always 'same'
Ordering
The order of the Norm/Conv/Dropout/Activation layers can be chosen
with the argument order. For example:
order='ncdax': Norm -> Conv -> Dropout -> Activation -> Attentionorder='andc': Activation -> Norm -> Dropout -> Conv
| PARAMETER | DESCRIPTION |
|---|---|
ndim |
Number of spatial dimensions
TYPE:
|
inp_channels |
Number of input features
TYPE:
|
out_channels |
Number of output features
TYPE:
|
kernel_size |
Kernel size
TYPE:
|
dilation |
Dilation size
TYPE:
|
bias |
Include a bias term
TYPE:
|
activation |
Activation function
TYPE:
|
norm |
Normalization function ('batch', 'instance', 'layer')
TYPE:
|
dropout |
Dropout probability
TYPE:
|
attention |
Attention layer
TYPE:
|
compression |
Compression ratio of the attention layer
TYPE:
|
order |
Modules order (permutation of 'ncdax')
TYPE:
|
separable |
Use a separable (or cross-hair) convolution
TYPE:
|
| PARAMETER | DESCRIPTION |
|---|---|
optc |
Other convolution parameters
TYPE:
|
optn |
Other nomralization parameters
TYPE:
|
optd |
Other dropout parameters
TYPE:
|
opta |
Other activation parameters
TYPE:
|
optx |
Other attention parameters
TYPE:
|
Source code in cassetta/layers/convblocks.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | |
forward
| PARAMETER | DESCRIPTION |
|---|---|
inp |
Input tensor
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
out
|
Output downsampled tensor
TYPE:
|
Source code in cassetta/layers/convblocks.py
ConvGroup
ConvGroup(ndim, channels, nb_conv=1, recurrent=False, residual=False, kernel_size=3, dilation=1, bias=True, activation='ReLU', norm=None, dropout=None, attention=None, compression=16, order='ncdax', separable=False, skip=0)
Bases: ModuleGroup
Multiple convolution blocks stacked together
Diagram
flowchart LR
subgraph nb_blocks
2("ConvBlock 1"):::w --> 3["C"] ---
4("ConvBlock 2"):::w --> 5["C"] ---
6("..."):::n --> 7["C"] ---
8("ConvBlock N"):::w
end
1["C [+S]"]:::i --- 2
8 ---> 9["C"]:::o
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef w fill:papayawhip,stroke:peachpuff;
classDef d fill:lightcyan,stroke:lightblue;
classDef n fill:none,stroke:none;
flowchart LR
subgraph nb_blocks
2("ConvBlock 1"):::w --> 3["C"] ---
4(("+")):::d --> 5["C"] ---
6("ConvBlock 2"):::w --> 7["C"] ---
8(("+")):::d --> 9["C"] ---
10("..."):::n --> 11["C"] ---
12("ConvBlock N"):::w --> 13["C"] ---
14(("+")):::d
end
1["C [+S]"]:::i --- 2
1 --- 4
5 --- 8
11 --- 14
14 ---> 15["C"]:::o
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef w fill:papayawhip,stroke:peachpuff;
classDef d fill:lightcyan,stroke:lightblue;
classDef n fill:none,stroke:none;
The recurrent variant shares weights across blocks
The number of channels is preserved throughout
Padding is always 'same'
| PARAMETER | DESCRIPTION |
|---|---|
ndim |
Number of spatial dimensions
TYPE:
|
channels |
Number of input and output features
TYPE:
|
nb_conv |
Number of convolution blocks
TYPE:
|
recurrent |
Recurrent network: share weights across blocks
TYPE:
|
residual |
Use residual connections between blocks
TYPE:
|
kernel_size |
Kernel size
TYPE:
|
dilation |
Dilation size
TYPE:
|
bias |
Include a bias term
TYPE:
|
activation |
Activation function
TYPE:
|
norm |
Normalization function ('batch', 'instance', 'layer')
TYPE:
|
dropout |
Dropout probability
TYPE:
|
attention |
Attention layer
TYPE:
|
compression |
Compression ratio of the attention layer
TYPE:
|
order |
Modules order (permutation of 'ncdax')
TYPE:
|
separable |
Use a separable (or cross-hair) convolution
TYPE:
|
skip |
Number of additional skipped channels in the input tensor.
TYPE:
|
Source code in cassetta/layers/convblocks.py
348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | |
DownGroup
Bases: Sequential
A downsampling step followed by a bunch of layers.
Diagram
flowchart LR
i["[C<sub>inp</sub>, W]"]:::i ---d("Down"):::w-->
1["[C<sub>mid</sub>, W/2]"] ---b("Block"):::w-->
o["[C<sub>out</sub>, W/2]"]:::o
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef w fill:papayawhip,stroke:peachpuff;
classDef d fill:lightcyan,stroke:lightblue;
classDef n fill:none,stroke:none;
| PARAMETER | DESCRIPTION |
|---|---|
module_down |
A downsamlping layer, such as
[
TYPE:
|
module_block |
A block of layers, that typically preserve the input shape,
such as [
TYPE:
|
Source code in cassetta/layers/convblocks.py
forward
| PARAMETER | DESCRIPTION |
|---|---|
inp |
Input tensor
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
out
|
Output downsampled tensor
TYPE:
|
indices
|
Indices, if
TYPE:
|
Source code in cassetta/layers/convblocks.py
DownConvGroup
DownConvGroup(ndim, inp_channels, out_channels=None, factor=2, mode='interpol', nb_conv=1, kernel_size=3, dilation=1, recurrent=False, residual=False, bias=True, activation='ReLU', norm=None, dropout=None, attention=None, compression=16, order='ncdax', separable=False, **down_options)
Bases: DownGroup
A downsampling step followed by a series of convolution blocks
Diagram
flowchart LR
subgraph "<code>nb_conv</code>"
2("ConvBlock 1"):::w --> 3["[C<sub>out</sub>, W/2]"] ---
4("ConvBlock 2"):::w --> 5["[C<sub>out</sub>, W/2]"] ---
6("..."):::n --> 7["[C<sub>out</sub>, W/2]"] ---
8("ConvBlock N"):::w
end
i["[C<sub>inp</sub>, W]"]:::i ---d("Down"):::w-->
od["[C<sub>out</sub>, W/2]"] ---2
8 ---> 9["[C<sub>out</sub>, W/2]"]:::o
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef w fill:papayawhip,stroke:peachpuff;
classDef d fill:lightcyan,stroke:lightblue;
classDef n fill:none,stroke:none;
flowchart LR
subgraph "<code>nb_conv</code>"
2("ConvBlock 1"):::w --> 3["[C<sub>out</sub>, W/2]"] ---
4(("+")):::d --> 5["[C<sub>out</sub>, W/2]"] ---
6("ConvBlock 2"):::w --> 7["[C<sub>out</sub>, W/2]"] ---
8(("+")):::d --> 9["[C<sub>out</sub>, W/2]"] ---
10("..."):::n --> 11["[C<sub>out</sub>, W/2]"] ---
12("ConvBlock N"):::w --> 13["[C<sub>out</sub>, W/2]"] ---
14(("+")):::d
end
i["[C<sub>inp</sub>, W]"]:::i ---d("Down"):::w-->
od["[C<sub>out</sub>, W/2]"] ---2
od --- 4
5 --- 8
11 --- 14
14 ---> 15["[C<sub>out</sub>, W/2]"]:::o
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef w fill:papayawhip,stroke:peachpuff;
classDef d fill:lightcyan,stroke:lightblue;
classDef n fill:none,stroke:none;
| PARAMETER | DESCRIPTION |
|---|---|
ndim |
Number of spatial dimensions
TYPE:
|
inp_channels |
Number of input channels
TYPE:
|
out_channels |
Number of output channels
TYPE:
|
factor |
Downsampling factor
TYPE:
|
mode |
Downsampling mode |
nb_conv |
Number of convolution blocks
TYPE:
|
kernel_size |
Kernel size
TYPE:
|
dilation |
Dilation size
TYPE:
|
recurrent |
Recurrent network: share weights across blocks
TYPE:
|
residual |
Use residual connections between blocks
TYPE:
|
bias |
Include a bias term
TYPE:
|
activation |
Activation function
TYPE:
|
norm |
Normalization function ('batch', 'instance', 'layer')
TYPE:
|
dropout |
Dropout probability
TYPE:
|
sqzex |
Squeeze & Excitation layer
TYPE:
|
compression |
Compression ratio of the Squeeze & Excitation layer
TYPE:
|
order |
Modules order (permutation of 'ncdax')
TYPE:
|
separable |
Use a separable (or cross-hair) convolution
TYPE:
|
| PARAMETER | DESCRIPTION |
|---|---|
interpolation |
Spline order
TYPE:
|
bound |
Boundary conditions
TYPE:
|
prefilter |
Perform proper interpolation by applying spline preflitering
|
return_indices |
Return argmax indices
|
Source code in cassetta/layers/convblocks.py
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 | |
UpGroup
Bases: Sequential
An upsampling step followed by a bunch of layers.
Diagram
flowchart LR
i["[C<sub>inp</sub>, W]"]:::i ---d("Up"):::w-->
1["[C<sub>mid</sub>, W*2]"] ---b("Block"):::w-->
o["[C<sub>out</sub>, W*2]"]:::o
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef w fill:papayawhip,stroke:peachpuff;
classDef d fill:lightcyan,stroke:lightblue;
classDef n fill:none,stroke:none;
flowchart LR
i["[C<sub>inp</sub>, W]"]:::i ---d("Up"):::w-->
1["[C<sub>mid</sub>, W*2]"]
s["[C<sub>mid</sub>, W*2]"]:::i
1 & s --- c(("c")):::d --->
2["[C<sub>mid</sub>*2, W*2]"] ---b("Block"):::w-->
o["[C<sub>out</sub>, W*2]"]:::o
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef w fill:papayawhip,stroke:peachpuff;
classDef d fill:lightcyan,stroke:lightblue;
classDef n fill:none,stroke:none;
flowchart LR
i["[C<sub>inp</sub>, W]"]:::i ---d("Up"):::w-->
1["[C<sub>mid</sub>, W*2]"]
s["[C<sub>mid</sub>, W*2]"]:::i
1 & s --- c(("+")):::d --->
2["[C<sub>mid</sub>, W*2]"] ---b("Block"):::w-->
o["[C<sub>out</sub>, W*2]"]:::o
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef w fill:papayawhip,stroke:peachpuff;
classDef d fill:lightcyan,stroke:lightblue;
classDef n fill:none,stroke:none;
| PARAMETER | DESCRIPTION |
|---|---|
module_up |
An upsampling layer, such as
[
TYPE:
|
module_block |
A block of layers, that typically preserve the input shape,
such as [
TYPE:
|
skip |
Whether to concatenate (
TYPE:
|
Source code in cassetta/layers/convblocks.py
forward
| PARAMETER | DESCRIPTION |
|---|---|
inp |
Input tensor
TYPE:
|
*skips |
Skipped tensors
TYPE:
|
| PARAMETER | DESCRIPTION |
|---|---|
indices |
Unpool indices. Only if
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
out
|
Output downsampled tensor
TYPE:
|
Source code in cassetta/layers/convblocks.py
UpConvGroup
UpConvGroup(ndim, inp_channels, out_channels=None, factor=2, skip=0, mode='interpol', nb_conv=1, kernel_size=3, dilation=1, recurrent=False, residual=False, bias=True, activation='ReLU', norm=None, dropout=False, attention=None, compression=16, order='ncdax', separable=False, **up_options)
Bases: UpGroup
A upsampling step followed by a series of convolution blocks, potentially with a skip connection
Diagram
flowchart LR
subgraph "<code>nb_conv</code>"
2("ConvBlock 1"):::w --> 3["[C<sub>out</sub>, W*2]"] ---
4("ConvBlock 2"):::w --> 5["[C<sub>out</sub>, W*2]"] ---
6("..."):::n --> 7["[C<sub>out</sub>, W*2]"] ---
8("ConvBlock N"):::w
end
i["[C<sub>inp</sub>, W]"]:::i ---d("Up"):::w-->
1["[C<sub>out</sub>, W*2]"] --- 2
8 ---> o["[C<sub>out</sub>, W*2]"]:::o
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef w fill:papayawhip,stroke:peachpuff;
classDef d fill:lightcyan,stroke:lightblue;
classDef n fill:none,stroke:none;
flowchart LR
subgraph "<code>nb_conv</code>"
2("ConvBlock 1"):::w --> 3["[C<sub>out</sub>, W*2]"] ---
4("ConvBlock 2"):::w --> 5["[C<sub>out</sub>, W*2]"] ---
6("..."):::n --> 7["[C<sub>out</sub>, W*2]"] ---
8("ConvBlock N"):::w
end
i["[C<sub>inp</sub>, W]"]:::i ---d("Up"):::w-->
1["[C<sub>out</sub>, W*2]"]
s["[C<sub>out</sub>, W*2]"]:::i
1 & s --- c(("c")):::d ---> x["[C<sub>out</sub>*2, W*2]"] --- 2
8 ---> o["[C<sub>out</sub>, W*2]"]:::o
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef w fill:papayawhip,stroke:peachpuff;
classDef d fill:lightcyan,stroke:lightblue;
classDef n fill:none,stroke:none;
flowchart LR
subgraph "<code>nb_conv</code>"
2("ConvBlock 1"):::w --> 3["[C<sub>out</sub>, W*2]"] ---
4("ConvBlock 2"):::w --> 5["[C<sub>out</sub>, W*2]"] ---
6("..."):::n --> 7["[C<sub>out</sub>, W*2]"] ---
8("ConvBlock N"):::w
end
i["[C<sub>inp</sub>, W]"]:::i ---d("Up"):::w-->
1["[C<sub>out</sub>, W*2]"]
s["[C<sub>out</sub>, W*2]"]:::i
1 & s --- c(("+")):::d ---> x["[C<sub>out</sub>, W*2]"] --- 2
8 ---> o["[C<sub>out</sub>, W*2]"]:::o
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef w fill:papayawhip,stroke:peachpuff;
classDef d fill:lightcyan,stroke:lightblue;
classDef n fill:none,stroke:none;
| PARAMETER | DESCRIPTION |
|---|---|
ndim |
Number of spatial dimensions
TYPE:
|
inp_channels |
Number of input channels
TYPE:
|
out_channels |
Number of output channels
TYPE:
|
factor |
Downsampling factor
TYPE:
|
skip |
Number of channels to concatenate in the skip connection. If 0 and skip tensors are provided, will try to add them instead of cat.
TYPE:
|
mode |
Downsampling mode |
nb_conv |
Number of convolution blocks
TYPE:
|
kernel_size |
Kernel size
TYPE:
|
dilation |
Dilation size
TYPE:
|
recurrent |
Recurrent network: share weights across blocks
TYPE:
|
residual |
Use residual connections between blocks
TYPE:
|
bias |
Include a bias term
TYPE:
|
activation |
Activation function
TYPE:
|
norm |
Normalization function ('batch', 'instance', 'layer')
TYPE:
|
dropout |
Dropout probability
TYPE:
|
order |
Modules order (permutation of 'ncdax')
TYPE:
|
separable |
Use a separable (or cross-hair) convolution
TYPE:
|
| PARAMETER | DESCRIPTION |
|---|---|
interpolation |
Spline order
TYPE:
|
bound |
Boundary conditions
TYPE:
|
prefilter |
Perform proper interpolation by applying spline preflitering
|
Source code in cassetta/layers/convblocks.py
838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 | |
cassetta.layers.dropout
ChannelDropout
Bases: _DropoutNd
forward
| PARAMETER | DESCRIPTION |
|---|---|
inp |
Input tensor
TYPE:
|
out |
Output tensor
TYPE:
|
Source code in cassetta/layers/dropout.py
make_dropout
Instantiate a (channel) dropout module.
| PARAMETER | DESCRIPTION |
|---|---|
dropout |
An already instantiated
TYPE:
|
kwargs |
Additional parameters to pass to the constructor or function.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
dropout
|
An instantiated
TYPE:
|
Source code in cassetta/layers/dropout.py
cassetta.layers.interpol
GridPull
Bases: Module
Deform an image using a coordinates field.
| PARAMETER | DESCRIPTION |
|---|---|
interpolation |
Interpolation order.
TYPE:
|
bound |
Boundary conditions.
TYPE:
|
extrapolate |
Extrapolate out-of-bound data.
TYPE:
|
prefilter |
Apply spline pre-filter (= interpolates the input)
TYPE:
|
Source code in cassetta/layers/interpol.py
forward
Sample an image.
If the input dtype is not a floating point type, the input image is assumed to contain labels. Then, unique labels are extracted and resampled individually, making them soft labels. Finally, the label map is reconstructed from the individual soft labels by assigning the label with maximum soft value.
| PARAMETER | DESCRIPTION |
|---|---|
input |
Input image.
TYPE:
|
grid |
Coordinate field, in voxels.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
output
|
Deformed image.
TYPE:
|
Source code in cassetta/layers/interpol.py
FlowPull
Bases: GridPull
Deform an image using a displacement field
| PARAMETER | DESCRIPTION |
|---|---|
interpolation |
Interpolation order.
TYPE:
|
bound |
Boundary conditions.
TYPE:
|
extrapolate |
Extrapolate out-of-bound data.
TYPE:
|
prefilter |
Apply spline pre-filter (= interpolates the input)
TYPE:
|
Source code in cassetta/layers/interpol.py
forward
Sample an image.
If the input dtype is not a floating point type, the input image is assumed to contain labels. Then, unique labels are extracted and resampled individually, making them soft labels. Finally, the label map is reconstructed from the individual soft labels by assigning the label with maximum soft value.
| PARAMETER | DESCRIPTION |
|---|---|
input |
Input image.
TYPE:
|
flow |
Displacement field, in voxels.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
output
|
Deformed image.
TYPE:
|
Source code in cassetta/layers/interpol.py
GridPush
Bases: Module
Splat an image using a coordinates field.
| PARAMETER | DESCRIPTION |
|---|---|
interpolation |
Interpolation order.
TYPE:
|
bound |
Boundary conditions.
TYPE:
|
extrapolate |
Extrapolate out-of-bound data.
TYPE:
|
prefilter |
Apply spline pre-filter (= interpolates the input)
TYPE:
|
Source code in cassetta/layers/interpol.py
forward
Splat an image.
| PARAMETER | DESCRIPTION |
|---|---|
input |
Input image.
TYPE:
|
grid |
Coordinate field, in voxels.
TYPE:
|
shape |
Output spatial shape.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
output
|
Splatted image.
TYPE:
|
Source code in cassetta/layers/interpol.py
FlowPush
Bases: GridPush
Splat an image using a displacement field
| PARAMETER | DESCRIPTION |
|---|---|
interpolation |
Interpolation order.
TYPE:
|
bound |
Boundary conditions.
TYPE:
|
extrapolate |
Extrapolate out-of-bound data.
TYPE:
|
prefilter |
Apply spline pre-filter (= interpolates the input)
TYPE:
|
Source code in cassetta/layers/interpol.py
forward
Splat an image.
| PARAMETER | DESCRIPTION |
|---|---|
input |
Input image.
TYPE:
|
flow |
Displacement field, in voxels.
TYPE:
|
shape |
Output spatial shape
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
output
|
Deformed image.
TYPE:
|
Source code in cassetta/layers/interpol.py
Resize
Resize(factor=None, shape=None, anchor='edge', interpolation='linear', bound='zero', extrapolate=True, prefilter=True)
Bases: Module
Resize (interpolate) an image
Notes
- A least one of
factorandshapemust be specified - If
anchor in ('center', 'edge'), exactly one offactororshapemust be specified. - If
anchor in ('first', 'last'),factormust be provided even ifshapeis specified. - Because of rounding, it is in general not assured that
resize(resize(x, f), 1/f)returns a tensor with the same shape as x.
edge center first last
e - + - + - e + - + - + - + + - + - + - + + - + - + - +
| . | . | . | | c | . | c | | f | . | . | | . | . | . |
+ _ + _ + _ + + _ + _ + _ + + _ + _ + _ + + _ + _ + _ +
| . | . | . | | . | . | . | | . | . | . | | . | . | . |
+ _ + _ + _ + + _ + _ + _ + + _ + _ + _ + + _ + _ + _ +
| . | . | . | | c | . | c | | . | . | . | | . | . | l |
e _ + _ + _ e + _ + _ + _ + + _ + _ + _ + + _ + _ + _ +
| PARAMETER | DESCRIPTION |
|---|---|
factor |
Resizing factor
TYPE:
|
shape |
Output shape
TYPE:
|
anchor |
TYPE:
|
interpolation |
Interpolation order.
TYPE:
|
bound |
Boundary conditions.
TYPE:
|
extrapolate |
Extrapolate out-of-bound data.
TYPE:
|
prefilter |
Apply spline pre-filter (= interpolates the input)
TYPE:
|
Source code in cassetta/layers/interpol.py
forward
Resize an image
| PARAMETER | DESCRIPTION |
|---|---|
input |
Input image
TYPE:
|
| PARAMETER | DESCRIPTION |
|---|---|
shape |
Output shape. If not provided at call time, use self.shape
TYPE:
|
| PARAMETER | DESCRIPTION |
|---|---|
output |
Resized image
TYPE:
|
Source code in cassetta/layers/interpol.py
Restrict
Restrict(factor=None, shape=None, anchor='edge', interpolation='linear', bound='zero', reduce_sum=False)
Bases: Module
Restrict an image (adjoint of resize)
Notes
- A least one of
factorandshapemust be specified - If
anchor in ('center', 'edge'), exactly one offactororshapemust be specified. - If
anchor in ('first', 'last'),factormust be provided even ifshapeis specified. - Because of rounding, it is in general not assured that
resize(resize(x, f), 1/f)returns a tensor with the same shape as x.
edge center first last
e - + - + - e + - + - + - + + - + - + - + + - + - + - +
| . | . | . | | c | . | c | | f | . | . | | . | . | . |
+ _ + _ + _ + + _ + _ + _ + + _ + _ + _ + + _ + _ + _ +
| . | . | . | | . | . | . | | . | . | . | | . | . | . |
+ _ + _ + _ + + _ + _ + _ + + _ + _ + _ + + _ + _ + _ +
| . | . | . | | c | . | c | | . | . | . | | . | . | l |
e _ + _ + _ e + _ + _ + _ + + _ + _ + _ + + _ + _ + _ +
| PARAMETER | DESCRIPTION |
|---|---|
factor |
Resizing factor
TYPE:
|
shape |
Output shape
TYPE:
|
anchor |
TYPE:
|
interpolation |
Interpolation order.
TYPE:
|
bound |
Boundary conditions.
TYPE:
|
reduce_sum |
Do not normalize by the number of accumulated values per voxel
TYPE:
|
Source code in cassetta/layers/interpol.py
forward
Restrict an image
| PARAMETER | DESCRIPTION |
|---|---|
input |
Input image
TYPE:
|
| PARAMETER | DESCRIPTION |
|---|---|
shape |
Output shape. If not provided at call time, use self.shape
TYPE:
|
| PARAMETER | DESCRIPTION |
|---|---|
output |
Restricted image
TYPE:
|
Source code in cassetta/layers/interpol.py
ResizeFlow
ResizeFlow(factor=None, shape=None, anchor='edge', interpolation='linear', bound='dft', extrapolate=True, prefilter=True)
Bases: Resize
Resize (interpolate) a displacement field
Source code in cassetta/layers/interpol.py
forward
Resize a displacement field. The magnitude of the displacements gets rescaled as well.
| PARAMETER | DESCRIPTION |
|---|---|
flow |
Input displacement field
TYPE:
|
| PARAMETER | DESCRIPTION |
|---|---|
shape |
Output shape. If not provided at call time, use self.shape
TYPE:
|
| PARAMETER | DESCRIPTION |
|---|---|
output |
Resized displacement field
TYPE:
|
Source code in cassetta/layers/interpol.py
ValueToCoeff
Bases: Module
Compute spline coefficients from values
| PARAMETER | DESCRIPTION |
|---|---|
interpolation |
Interpolation order.
TYPE:
|
bound |
Boundary conditions.
TYPE:
|
Source code in cassetta/layers/interpol.py
forward
| PARAMETER | DESCRIPTION |
|---|---|
input |
Input image of values
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
output
|
Input image of spline coefficients
TYPE:
|
Source code in cassetta/layers/interpol.py
CoeffToValue
Bases: Module
Compute values from spline coefficients
| PARAMETER | DESCRIPTION |
|---|---|
interpolation |
Interpolation order.
TYPE:
|
bound |
Boundary conditions.
TYPE:
|
Source code in cassetta/layers/interpol.py
forward
| PARAMETER | DESCRIPTION |
|---|---|
input |
Input image of spline coefficients
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
output
|
Input image of values
TYPE:
|
Source code in cassetta/layers/interpol.py
FlowExp
Bases: Module
Exponentiate a stationary velocity field
| PARAMETER | DESCRIPTION |
|---|---|
nsteps |
Number of scaling and squaring steps
TYPE:
|
interpolation |
Interpolation order.
TYPE:
|
bound |
Boundary conditions.
TYPE:
|
extrapolate |
Extrapolate out-of-bound data.
TYPE:
|
coeff |
If True, the input velocity image contains spline coefficients, and spline coefficients will also be returned. If False, the input velocity image contains actual values, and values will also be returned.
TYPE:
|
Source code in cassetta/layers/interpol.py
forward
Exponentiate the SVF
| PARAMETER | DESCRIPTION |
|---|---|
flow |
Stationary velocity field
TYPE:
|
Source code in cassetta/layers/interpol.py
FlowMomentum
FlowMomentum(absolute=0, membrane=0, bending=0, div=0, shears=0, norm=True, interpolation='linear', bound='dft')
Bases: Module
Compute the momentum of a displacement field
| PARAMETER | DESCRIPTION |
|---|---|
absolute |
Penalty on absolute displacement
TYPE:
|
membrane |
Penalty on first derivatives
TYPE:
|
bending |
Penalty on second derivatives
TYPE:
|
div |
Penalty on volume changes
TYPE:
|
shears |
Penalty on shears
TYPE:
|
norm |
If True, compute the average energy across the field of view. Otherwise, compute the sum (integral) of the energy across the FOV.
TYPE:
|
interpolation |
Spline order
TYPE:
|
bound |
Boundary conditions
TYPE:
|
Source code in cassetta/layers/interpol.py
forward
| PARAMETER | DESCRIPTION |
|---|---|
flow |
Spline coefficients of a displacement field
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
mom
|
Momentum field
TYPE:
|
Source code in cassetta/layers/interpol.py
FlowLoss
FlowLoss(absolute=0, membrane=0, bending=0, div=0, shears=0, norm=True, interpolation='linear', bound='dft')
Bases: FlowMomentum
Compute the regularization loss of a displacement field
| PARAMETER | DESCRIPTION |
|---|---|
absolute |
Penalty on absolute displacement
TYPE:
|
membrane |
Penalty on first derivatives
TYPE:
|
bending |
Penalty on second derivatives
TYPE:
|
div |
Penalty on volume changes
TYPE:
|
shears |
Penalty on shears
TYPE:
|
norm |
If True, compute the average energy across the field of view. Otherwise, compute the sum (integral) of the energy across the FOV.
TYPE:
|
interpolation |
Spline order
TYPE:
|
bound |
Boundary conditions
TYPE:
|
Source code in cassetta/layers/interpol.py
forward
| PARAMETER | DESCRIPTION |
|---|---|
flow |
Spline coefficients of a displacement field
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
loss
|
loss -- averaged across batch elements
TYPE:
|
Source code in cassetta/layers/interpol.py
SplineUp2
Bases: Module
MSE-minmizing upsampling of a displacement field -- by a factor 2
| PARAMETER | DESCRIPTION |
|---|---|
interpolation |
Spline order
TYPE:
|
bound |
Boundary conditions
TYPE:
|
Source code in cassetta/layers/interpol.py
forward
| PARAMETER | DESCRIPTION |
|---|---|
flow |
Spline coefficients of a displacement field
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
flow2
|
Spline coefficients of a larger displacement field
TYPE:
|
Source code in cassetta/layers/interpol.py
cassetta.layers.linear
Linear
Bases: Module
Linear layer.
We reimplement nn.Linear so that the dimension that it operates
upon is the second (by default) instead of the last. This makes it
more compatible with vision applications.
| PARAMETER | DESCRIPTION |
|---|---|
inp_channels |
Number of input channels
TYPE:
|
out_channels |
Number of output channels
TYPE:
|
bias |
Include a bias term
TYPE:
|
dim |
Dimension along which to operate
TYPE:
|
| PARAMETER | DESCRIPTION |
|---|---|
device |
Weight's device
TYPE:
|
dtype |
Weight's data type
TYPE:
|
Source code in cassetta/layers/linear.py
forward
| PARAMETER | DESCRIPTION |
|---|---|
inp |
Input tensor
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
out
|
Output tensor
TYPE:
|
Source code in cassetta/layers/linear.py
LazyLinear
Bases: LazyModuleMixin, Linear
A linear layer whose weights get allocated lazily, on first call.
This allows the number of input channels to be automatically determined at run time.
We reimplement nn.LazyLinear so that the dimension that it operates
upon is the second (by default) instead of the last. This makes it
more compatible with vision applications.
We also allow the number of output channels to be set lazily.
| PARAMETER | DESCRIPTION |
|---|---|
out_channels |
Number of output channels. If a function, takes the number of input channels and returns the number of output channels.
TYPE:
|
bias |
Include a bias term
TYPE:
|
dim |
Dimension along which to operate
TYPE:
|
| PARAMETER | DESCRIPTION |
|---|---|
device |
Weight's device
TYPE:
|
dtype |
Weight's data type
TYPE:
|
Source code in cassetta/layers/linear.py
cassetta.layers.norm
BatchNorm
BatchNorm(channels, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True, device=None, dtype=None)
Bases: _BatchNorm
| PARAMETER | DESCRIPTION |
|---|---|
nb_chanels |
Number of input channels.
TYPE:
|
eps |
Value added to the denominator for numerical stability.
TYPE:
|
momentum |
The value used for the
TYPE:
|
affine |
Use learnable affine parameters.
TYPE:
|
track_running_stats |
Track the running mean and variance. If
TYPE:
|
Source code in cassetta/layers/norm.py
InstanceNorm
InstanceNorm(channels, eps=1e-05, momentum=0.1, affine=False, track_running_stats=False, device=None, dtype=None)
Bases: _InstanceNorm
| PARAMETER | DESCRIPTION |
|---|---|
nb_chanels |
Number of input channels.
TYPE:
|
eps |
Value added to the denominator for numerical stability.
TYPE:
|
momentum |
The value used for the
TYPE:
|
affine |
Use learnable affine parameters.
TYPE:
|
track_running_stats |
Track the running mean and variance. If
TYPE:
|
Source code in cassetta/layers/norm.py
forward
| PARAMETER | DESCRIPTION |
|---|---|
inp |
Input tensor
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
out
|
Output tensor
TYPE:
|
Source code in cassetta/layers/norm.py
LayerNorm
Bases: GroupNorm
| PARAMETER | DESCRIPTION |
|---|---|
nb_chanels |
Number of input channels.
TYPE:
|
eps |
Value added to the denominator for numerical stability.
TYPE:
|
affine |
Use learnable affine parameters.
TYPE:
|
Source code in cassetta/layers/norm.py
make_norm
Instantiate a normalization module.
To be accepted in a nn.Sequential module or in a nn.ModuleList,
a norm must be a nn.Module. This function takes other
forms of "norm parameters" that are typically passed to the
constructor of larger models, and generate the corresponding
instantiated Module.
A norm-like value can be a nn.Module subclass, which is
then instantiated, or a callable function that returns an
instantiated Module. It can also be the name of a none normalization:
"batch", "layer", or "instance".
It is useful to accept all these cases as they allow to either:
- have a learnable norm specific to this module
- have a learnable norm shared with other modules
- have a non-learnable norm
| PARAMETER | DESCRIPTION |
|---|---|
norm |
An already instantiated
TYPE:
|
channels |
Number of channels
TYPE:
|
affine |
Include a learnable affine transform.
TYPE:
|
kwargs |
Additional parameters to pass to the constructor or function.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
norm
|
An instantiated
TYPE:
|
Source code in cassetta/layers/norm.py
cassetta.layers.simple
Cat
Bases: Module
Concatenate tensors
Diagram
flowchart LR
subgraph Inputs
i1["C<sub>1</sub>"]:::i
i2["C<sub>2</sub>"]:::i
i3["..."]:::n
i4["C<sub>N</sub>"]:::i
end
i1 & i2 & i3 & i4 ---z(("c")):::d--->
o["C<sub>1</sub> + C<sub>2</sub> + ... + C<sub>N</sub>"]:::o
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef d fill:lightcyan,stroke:lightblue;
classDef w fill:papayawhip,stroke:peachpuff;
classDef n fill:none,stroke:none;
| PARAMETER | DESCRIPTION |
|---|---|
dim |
Dimension to concatenate. Default is 1, the channel dimension.
TYPE:
|
Source code in cassetta/layers/simple.py
forward
| PARAMETER | DESCRIPTION |
|---|---|
*inputs |
A series of tensors
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
output
|
A single concatenated tensor
TYPE:
|
Add
Bases: Module
Add tensors
Diagram
flowchart LR
subgraph Inputs
i1["C"]:::i
i2["C"]:::i
i3["..."]:::n
i4["C"]:::i
end
i1 & i2 & i3 & i4 ---z(("+")):::d--->
o["C"]:::o
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef d fill:lightcyan,stroke:lightblue;
classDef w fill:papayawhip,stroke:peachpuff;
classDef n fill:none,stroke:none;
forward
| PARAMETER | DESCRIPTION |
|---|---|
*inputs |
A series of tensors
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
output
|
A single summed tensor
TYPE:
|
Split
Bases: Module
Split tensor
Diagram
flowchart LR
subgraph Outputs
o1["C"]:::o
o2["C"]:::o
o3["..."]:::n
o4["C"]:::o
end
i["NxC"]:::i ---z(("s")):::d---> o1 & o2 & o3 & o4
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef d fill:lightcyan,stroke:lightblue;
classDef w fill:papayawhip,stroke:peachpuff;
classDef n fill:none,stroke:none;
| PARAMETER | DESCRIPTION |
|---|---|
nb_chunks |
Number of output tensors
TYPE:
|
dim |
Dimension to chunk. Default is 1, the channel dimension.
TYPE:
|
Source code in cassetta/layers/simple.py
forward
| PARAMETER | DESCRIPTION |
|---|---|
input |
The tensor to chunk
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
output
|
Tencor chunks
TYPE:
|
DoNothing
Bases: Module
A layer that does nothing
Diagram
flowchart LR
i["C"]:::i ---> o["C"]:::o
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
MoveDim
Hadamard
Bases: Module
Reparameterize tensors using the Hadamard transform: (x, y) -> (x + y, x - y)
Diagram
flowchart LR
x["C"]:::i
y["C"]:::i
x & y ---plus(("+")):::d---> oplus["C"]:::o
x & y ---minus(("-")):::d---> ominus["C"]:::o
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef d fill:lightcyan,stroke:lightblue;
classDef w fill:papayawhip,stroke:peachpuff;
classDef n fill:none,stroke:none;
flowchart LR
inp["2xC"]:::i ---split(("s")):::d---> x["C"] & y["C"]
x & y ---plus(("+")):::d---> oplus["C"]
x & y ---minus(("-")):::d---> ominus["C"]
oplus & ominus ---cat(("c")):::d---> o["2xC"]:::o
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef d fill:lightcyan,stroke:lightblue;
classDef w fill:papayawhip,stroke:peachpuff;
classDef n fill:none,stroke:none;
forward
Note
This layer can be applied to a single tensor, or to two tensors.
- If two tensors are provided, their Hadamard transform is computed, and two tensors are returned.
- If a single tensor is provided, it is split into two chunks, their Hadamard transform is computed, and the resulting chunks are concatenated and returned.
| PARAMETER | DESCRIPTION |
|---|---|
x |
One or two tensors
TYPE:
|
y |
One or two tensors
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
hx, hy : (B, C, *shape) tensor
|
One or two transformedtensors |
Source code in cassetta/layers/simple.py
ModuleSum
Bases: ModuleList
Apply modules in parallel and sum their outputs.
Diagram
flowchart LR
subgraph nb_blocks
2("Block 1"):::w --> 3["C"]
4("Block 2"):::w --> 5["C"]
6("..."):::n
8("Block N"):::w --> 9["C"]
end
1["C"]:::i --- 2 & 4 & 6 & 8
3 & 5 & 6 & 9 --- 10(("+")):::d
10 --> 11["C"]:::o
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef w fill:papayawhip,stroke:peachpuff;
classDef d fill:lightcyan,stroke:lightblue;
classDef n fill:none,stroke:none;
The output of all modules must have the same shape
forward
| PARAMETER | DESCRIPTION |
|---|---|
inp |
Input tensor
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
out
|
Output tensor
TYPE:
|
Source code in cassetta/layers/simple.py
ModuleGroup
Bases: Sequential
Multiple layers stacked together, eventually with residual connections.
Diagram
flowchart LR
subgraph nb_blocks
2("Block 1"):::w --> 3["C"] ---
4("Block 2"):::w --> 5["C"] ---
6("..."):::n --> 7["C"] ---
8("Block N"):::w
end
1["C"]:::i --- 2
8 ---> 9["C"]:::o
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef w fill:papayawhip,stroke:peachpuff;
classDef d fill:lightcyan,stroke:lightblue;
classDef n fill:none,stroke:none;
flowchart LR
subgraph nb_blocks
2("Block 1"):::w --> 3["C"] ---
4(("+")):::d --> 5["C"] ---
6("Block 2"):::w --> 7["C"] ---
8(("+")):::d --> 9["C"] ---
10("..."):::n --> 11["C"] ---
12("Block N"):::w --> 13["C"] ---
14(("+")):::d
end
1["C"]:::i --- 2
1 --- 4
5 --- 8
11 --- 14
14 ---> 15["C"]:::o
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef w fill:papayawhip,stroke:peachpuff;
classDef d fill:lightcyan,stroke:lightblue;
classDef n fill:none,stroke:none;
flowchart LR
subgraph nb_blocks
2("Block 1"):::w --> 3["C"] ---
4(("+")):::d --> 5["C"] ---
6("Block 2"):::w --> 7["C"] ---
8(("+")):::d --> 9["C"] ---
10("..."):::n --> 11["C"] ---
12("Block N"):::w --> 13["C"] ---
14(("+")):::d
end
1["C+S"]:::i --- 2
1 --- split(("s")):::d --> c["C"] & s["S"]
c --- 4
s --- void[" "]:::n
5 --- 8
11 --- 14
14 ---> 15["C"]:::o
classDef i fill:honeydew,stroke:lightgreen;
classDef o fill:mistyrose,stroke:lightpink;
classDef w fill:papayawhip,stroke:peachpuff;
classDef d fill:lightcyan,stroke:lightblue;
classDef n fill:none,stroke:none;
linkStyle 17 stroke:none;
The recurrent variant shares weights across blocks
The number of channels should be preserved throughout
The spatial size should be preserved throughout
| PARAMETER | DESCRIPTION |
|---|---|
blocks |
Number of blocks
TYPE:
|
residual |
Use residual connections between blocks
TYPE:
|
skip |
Number of additional skipped channels in the input tensor.
TYPE:
|
Source code in cassetta/layers/simple.py
forward
| PARAMETER | DESCRIPTION |
|---|---|
inp |
Input tensor
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
out
|
Output tensor
TYPE:
|
Source code in cassetta/layers/simple.py
GlobalPool
Bases: Module
Global pooling across spatial dimensions
Diagram
flowchart LR
1["`[B, C, W, H]`"] ---2("`GlobalPool`"):::d-->
3["`[B, C, 1, 1]`"]
classDef d fill:lightcyan,stroke:lightblue;
flowchart LR
1["`[B, C, W, H]`"] ---2("`GlobalPool`"):::d-->
3["`[B, C]`"]
classDef d fill:lightcyan,stroke:lightblue;
flowchart LR
1["`[B, C, W, H]`"] ---2("`GlobalPool`"):::d-->
3["`[B, 1, W, H]`"]
classDef d fill:lightcyan,stroke:lightblue;
| PARAMETER | DESCRIPTION |
|---|---|
reduction |
Reduction type
TYPE:
|
keepdim |
Keep spatial dimensions
TYPE:
|
dim |
Dimension(s) to pool
TYPE:
|
Source code in cassetta/layers/simple.py
forward
| PARAMETER | DESCRIPTION |
|---|---|
inp |
Input tensor
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
out
|
Output tensor
TYPE:
|
Source code in cassetta/layers/simple.py
cassetta.layers.updown
DownConv
Bases: Module
Downsample using a strided convolution.
This layer includes no activation/norm/dropout
| PARAMETER | DESCRIPTION |
|---|---|
ndim |
Number of spatial dimensions
TYPE:
|
inp_channels |
Number of input channels
TYPE:
|
out_channels |
Number of output channels
TYPE:
|
factor |
Downsampling factor
TYPE:
|
Source code in cassetta/layers/updown.py
forward
| PARAMETER | DESCRIPTION |
|---|---|
inp |
Input tensor
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
out
|
Output downsampled tensor
TYPE:
|
UpConv
Bases: Module
Upsample using a strided convolution.
This layer includes no activation/norm/dropout
| PARAMETER | DESCRIPTION |
|---|---|
ndim |
Number of spatial dimensions
TYPE:
|
inp_channels |
Number of input channels
TYPE:
|
out_channels |
Number of output channels
TYPE:
|
factor |
Downsampling factor
TYPE:
|
Source code in cassetta/layers/updown.py
forward
| PARAMETER | DESCRIPTION |
|---|---|
inp |
Input tensor
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
out
|
Output downsampled tensor
TYPE:
|
Source code in cassetta/layers/updown.py
DownPool
Bases: Sequential
Downsampling using max-pooling + channel expansion
This layer includes no activation/norm/dropout
| PARAMETER | DESCRIPTION |
|---|---|
ndim |
Number of spatial dimensions
TYPE:
|
inp_channels |
Number of input channels
TYPE:
|
out_channels |
Number of output channels
TYPE:
|
factor |
Downsampling factor
TYPE:
|
return_indices |
Return indices on top of pooled features
TYPE:
|
Source code in cassetta/layers/updown.py
forward
| PARAMETER | DESCRIPTION |
|---|---|
inp |
Input tensor
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
out
|
Output downsampled tensor
TYPE:
|
indices
|
Argmax of the maxpooling operation.
Only returned if
TYPE:
|
Source code in cassetta/layers/updown.py
UpPool
Bases: Sequential
Downsampling using max-pooling + channel expansion
This layer includes no activation/norm/dropout
| PARAMETER | DESCRIPTION |
|---|---|
ndim |
Number of spatial dimensions
TYPE:
|
inp_channels |
Number of input channels
TYPE:
|
out_channels |
Number of output channels
TYPE:
|
factor |
Downsampling factor
TYPE:
|
Source code in cassetta/layers/updown.py
forward
| PARAMETER | DESCRIPTION |
|---|---|
inp |
Input tensor
TYPE:
|
indices |
Indices returned by
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
out
|
Output upsampled tensor
TYPE:
|
Source code in cassetta/layers/updown.py
DownInterpol
DownInterpol(ndim, inp_channels, out_channels=None, factor=2, interpolation='linear', bound='zero', prefilter=True)
Bases: Sequential
Downsampling using spline interpolation + channel expansion
This layer includes no activation/norm/dropout
| PARAMETER | DESCRIPTION |
|---|---|
ndim |
Number of spatial dimensions
TYPE:
|
inp_channels |
Number of input channels
TYPE:
|
out_channels |
Number of output channels
TYPE:
|
factor |
Downsampling factor
TYPE:
|
interpolation |
Interpolation order.
TYPE:
|
bound |
Boundary conditions.
TYPE:
|
prefilter |
Apply spline pre-filter (= interpolates the input)
TYPE:
|
Source code in cassetta/layers/updown.py
UpInterpol
UpInterpol(ndim, inp_channels, out_channels=None, factor=2, interpolation='linear', bound='zero', prefilter=True)
Bases: Sequential
Upsampling using spline interpolation + channel expansion
This layer includes no activation/norm/dropout
| PARAMETER | DESCRIPTION |
|---|---|
ndim |
Number of spatial dimensions
TYPE:
|
inp_channels |
Number of input channels
TYPE:
|
out_channels |
Number of output channels
TYPE:
|
factor |
Downsampling factor
TYPE:
|
interpolation |
Interpolation order.
TYPE:
|
bound |
Boundary conditions.
TYPE:
|
prefilter |
Apply spline pre-filter (= interpolates the input)
TYPE:
|