MCPcopy Create free account
hub / github.com/Project-MONAI/MONAI / ResBlock

Class ResBlock

monai/networks/blocks/segresnet_block.py:44–96  ·  view source on GitHub ↗

ResBlock employs skip connection and two convolution blocks and is used in SegResNet based on `3D MRI brain tumor segmentation using autoencoder regularization `_.

Source from the content-addressed store, hash-verified

42
43
44class ResBlock(nn.Module):
45 """
46 ResBlock employs skip connection and two convolution blocks and is used
47 in SegResNet based on `3D MRI brain tumor segmentation using autoencoder regularization
48 <https://arxiv.org/pdf/1810.11654.pdf>`_.
49 """
50
51 def __init__(
52 self,
53 spatial_dims: int,
54 in_channels: int,
55 norm: tuple | str,
56 kernel_size: int = 3,
57 act: tuple | str = ("RELU", {"inplace": True}),
58 ) -> None:
59 """
60 Args:
61 spatial_dims: number of spatial dimensions, could be 1, 2 or 3.
62 in_channels: number of input channels.
63 norm: feature normalization type and arguments.
64 kernel_size: convolution kernel size, the value should be an odd number. Defaults to 3.
65 act: activation type and arguments. Defaults to ``RELU``.
66 """
67
68 super().__init__()
69
70 if kernel_size % 2 != 1:
71 raise AssertionError("kernel_size should be an odd number.")
72
73 self.norm1 = get_norm_layer(name=norm, spatial_dims=spatial_dims, channels=in_channels)
74 self.norm2 = get_norm_layer(name=norm, spatial_dims=spatial_dims, channels=in_channels)
75 self.act = get_act_layer(act)
76 self.conv1 = get_conv_layer(
77 spatial_dims, in_channels=in_channels, out_channels=in_channels, kernel_size=kernel_size
78 )
79 self.conv2 = get_conv_layer(
80 spatial_dims, in_channels=in_channels, out_channels=in_channels, kernel_size=kernel_size
81 )
82
83 def forward(self, x):
84 identity = x
85
86 x = self.norm1(x)
87 x = self.act(x)
88 x = self.conv1(x)
89
90 x = self.norm2(x)
91 x = self.act(x)
92 x = self.conv2(x)
93
94 x += identity
95
96 return x

Callers 4

_make_down_layersMethod · 0.90
_make_up_layersMethod · 0.90
test_shapeMethod · 0.90
test_ill_argMethod · 0.90

Calls

no outgoing calls

Tested by 2

test_shapeMethod · 0.72
test_ill_argMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…