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

Class MBConvBlock

monai/networks/nets/efficientnet.py:75–227  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

73
74
75class MBConvBlock(nn.Module):
76
77 def __init__(
78 self,
79 spatial_dims: int,
80 in_channels: int,
81 out_channels: int,
82 kernel_size: int,
83 stride: int,
84 image_size: list[int],
85 expand_ratio: int,
86 se_ratio: float | None,
87 id_skip: bool | None = True,
88 norm: str | tuple = ("batch", {"eps": 1e-3, "momentum": 0.01}),
89 drop_connect_rate: float | None = 0.2,
90 ) -> None:
91 """
92 Mobile Inverted Residual Bottleneck Block.
93
94 Args:
95 spatial_dims: number of spatial dimensions.
96 in_channels: number of input channels.
97 out_channels: number of output channels.
98 kernel_size: size of the kernel for conv ops.
99 stride: stride to use for conv ops.
100 image_size: input image resolution.
101 expand_ratio: expansion ratio for inverted bottleneck.
102 se_ratio: squeeze-excitation ratio for se layers.
103 id_skip: whether to use skip connection.
104 norm: feature normalization type and arguments. Defaults to batch norm.
105 drop_connect_rate: dropconnect rate for drop connection (individual weights) layers.
106
107 References:
108 [1] https://arxiv.org/abs/1704.04861 (MobileNet v1)
109 [2] https://arxiv.org/abs/1801.04381 (MobileNet v2)
110 [3] https://arxiv.org/abs/1905.02244 (MobileNet v3)
111 """
112 super().__init__()
113
114 # select the type of N-Dimensional layers to use
115 # these are based on spatial dims and selected from MONAI factories
116 conv_type = Conv["conv", spatial_dims]
117 adaptivepool_type = Pool["adaptiveavg", spatial_dims]
118
119 self.in_channels = in_channels
120 self.out_channels = out_channels
121 self.id_skip = id_skip
122 self.stride = stride
123 self.expand_ratio = expand_ratio
124 self.drop_connect_rate = drop_connect_rate
125
126 if (se_ratio is not None) and (0.0 < se_ratio <= 1.0):
127 self.has_se = True
128 self.se_ratio = se_ratio
129 else:
130 self.has_se = False
131
132 # Expansion phase (Inverted Bottleneck)

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…