Layers
Layer module.
This submodule contains layers used in the CAREamics models.
Conv_Block
Bases: Module
Convolution block used in UNets.
Convolution block consist of two convolution layers with optional batch norm, dropout and with a final activation function.
The parameters are directly mapped to PyTorch Conv2D and Conv3d parameters, see PyTorch torch.nn.Conv2d and torch.nn.Conv3d for more information.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
conv_dim
|
int
|
Number of dimension of the convolutions, 2 or 3. |
required |
in_channels
|
int
|
Number of input channels. |
required |
out_channels
|
int
|
Number of output channels. |
required |
intermediate_channel_multiplier
|
int
|
Multiplied for the number of output channels, by default 1. |
1
|
stride
|
int
|
Stride of the convolutions, by default 1. |
1
|
padding
|
int
|
Padding of the convolutions, by default 1. |
1
|
bias
|
bool
|
Bias of the convolutions, by default True. |
True
|
groups
|
int
|
Controls the connections between inputs and outputs, by default 1. |
1
|
activation
|
str
|
Activation function, by default "ReLU". |
'ReLU'
|
dropout_perc
|
float
|
Dropout percentage, by default 0. |
0
|
use_batch_norm
|
bool
|
Use batch norm, by default False. |
False
|
forward(x)
Forward pass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input tensor. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Output tensor. |
MaxBlurPool
Bases: Module
Compute pools and blurs and downsample a given feature map.
Inspired by Kornia MaxBlurPool implementation. Equivalent to
nn.Sequential(nn.MaxPool2d(...), BlurPool2D(...))
Parameters
dim : int Toggles between 2D and 3D. kernel_size : Union[tuple[int, int], int] Kernel size for max pooling. stride : int Stride for pooling. max_pool_size : int Max kernel size for max pooling. ceil_mode : bool Ceil mode, by default False. Set to True to match output size of conv2d.
forward(x)
Forward pass of the function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input tensor. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Output tensor. |
get_pascal_kernel_1d(kernel_size, norm=False, *, device=None, dtype=None)
Generate Yang Hui triangle (Pascal's triangle) for a given number.
Inspired by Kornia implementation. TODO link
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
kernel_size
|
int
|
Kernel size. |
required |
norm
|
bool
|
Normalize the kernel, by default False. |
False
|
device
|
Optional[device]
|
Device of the tensor, by default None. |
None
|
dtype
|
Optional[dtype]
|
Data type of the tensor, by default None. |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Pascal kernel. |
Examples:
>>> get_pascal_kernel_1d(1)
tensor([1.])
>>> get_pascal_kernel_1d(2)
tensor([1., 1.])
>>> get_pascal_kernel_1d(3)
tensor([1., 2., 1.])
>>> get_pascal_kernel_1d(4)
tensor([1., 3., 3., 1.])
>>> get_pascal_kernel_1d(5)
tensor([1., 4., 6., 4., 1.])
>>> get_pascal_kernel_1d(6)
tensor([ 1., 5., 10., 10., 5., 1.])