mednet.models.segment.make_layers¶
Functions
|
Convolution layer with kaiming uniform. |
|
Implement convtrans layer with kaiming uniform. |
|
ICNR init of |
|
Return |
Classes
|
Upsample by |
|
Unet block implementation. |
|
Combines Conv2d, ConvTransposed2d and Cropping. |
- mednet.models.segment.make_layers.conv_with_kaiming_uniform(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1)[source]¶
Convolution layer with kaiming uniform.
- Parameters:
in_channels – Number of input channels.
out_channels – Number of output channels.
kernel_size – The kernel size.
stride – The stride.
padding – The padding.
dilation – The dilation.
- Returns:
The convoluation layer.
- mednet.models.segment.make_layers.convtrans_with_kaiming_uniform(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1)[source]¶
Implement convtrans layer with kaiming uniform.
- Parameters:
in_channels – Number of input channels.
out_channels – Number of output channels.
kernel_size – The kernel size.
stride – The stride.
padding – The padding.
dilation – The dilation.
- Returns:
The convtrans layer.
- class mednet.models.segment.make_layers.UpsampleCropBlock(in_channels, out_channels, up_kernel_size, up_stride, up_padding, pixelshuffle=False)[source]¶
Bases:
Module
Combines Conv2d, ConvTransposed2d and Cropping. Simulates the caffe2 crop layer in the forward function.
Used for DRIU and HED.
- Parameters:
in_channels (
int
) – Number of channels of intermediate layer.out_channels (
int
) – Number of output channels.up_kernel_size (
int
) – Kernel size for transposed convolution.up_stride (
int
) – Stride for transposed convolution.up_padding (
int
) – Padding for transposed convolution.pixelshuffle (
bool
) – If True, uses PixelShuffleICNR upsampling.
- forward(x, input_res)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- mednet.models.segment.make_layers.ifnone(a, b)[source]¶
Return
a
ifa
is not None, otherwiseb
.- Parameters:
a – The first parameter.
b – The second parameter.
- Returns:
The parameter a if it is not None, else b.
- mednet.models.segment.make_layers.icnr(x, scale=2, init=<function kaiming_normal_>)[source]¶
ICNR init of
x
, withscale
andinit
function.https://docs.fast.ai/layers.html#PixelShuffleICNR.
- Parameters:
x – Tensor.
scale – Scale of the upsample.
init – Function used to initialize.
- class mednet.models.segment.make_layers.PixelShuffleICNR(ni, nf=None, scale=2)[source]¶
Bases:
Module
Upsample by
scale
fromni
filters tonf
(defaultni
), usingtorch.nn.PixelShuffle
,icnr
init, andweight_norm
.https://docs.fast.ai/layers.html#PixelShuffleICNR.
- Parameters:
- forward(x)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class mednet.models.segment.make_layers.UnetBlock(up_in_c, x_in_c, pixel_shuffle=False, middle_block=False)[source]¶
Bases:
Module
Unet block implementation.
- Parameters:
up_in_c – Number of input channels.
x_in_c – Number of cat channels.
pixel_shuffle – If True, uses a PixelShuffleICNR layer for upsampling.
middle_block – If True, uses a middle block for VGG based U-Net.
- forward(up_in, x_in)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Module
instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.