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

Method __init__

monai/networks/nets/resnet.py:217–288  ·  view source on GitHub ↗
(
        self,
        block: type[ResNetBlock | ResNetBottleneck] | str,
        layers: list[int],
        block_inplanes: list[int],
        spatial_dims: int = 3,
        n_input_channels: int = 3,
        conv1_t_size: tuple[int] | int = 7,
        conv1_t_stride: tuple[int] | int = 1,
        no_max_pool: bool = False,
        shortcut_type: str = "B",
        widen_factor: float = 1.0,
        num_classes: int = 400,
        feed_forward: bool = True,
        bias_downsample: bool = True,  # for backwards compatibility (also see PR #5477)
        act: str | tuple = ("relu", {"inplace": True}),
        norm: str | tuple = "batch",
    )

Source from the content-addressed store, hash-verified

215 """
216
217 def __init__(
218 self,
219 block: type[ResNetBlock | ResNetBottleneck] | str,
220 layers: list[int],
221 block_inplanes: list[int],
222 spatial_dims: int = 3,
223 n_input_channels: int = 3,
224 conv1_t_size: tuple[int] | int = 7,
225 conv1_t_stride: tuple[int] | int = 1,
226 no_max_pool: bool = False,
227 shortcut_type: str = "B",
228 widen_factor: float = 1.0,
229 num_classes: int = 400,
230 feed_forward: bool = True,
231 bias_downsample: bool = True, # for backwards compatibility (also see PR #5477)
232 act: str | tuple = ("relu", {"inplace": True}),
233 norm: str | tuple = "batch",
234 ) -> None:
235 super().__init__()
236
237 if isinstance(block, str):
238 if block == "basic":
239 block = ResNetBlock
240 elif block == "bottleneck":
241 block = ResNetBottleneck
242 else:
243 raise ValueError(f"Unknown block '{block}', use basic or bottleneck")
244
245 conv_type: type[nn.Conv1d | nn.Conv2d | nn.Conv3d] = Conv[Conv.CONV, spatial_dims]
246 pool_type: type[nn.MaxPool1d | nn.MaxPool2d | nn.MaxPool3d] = Pool[Pool.MAX, spatial_dims]
247 avgp_type: type[nn.AdaptiveAvgPool1d | nn.AdaptiveAvgPool2d | nn.AdaptiveAvgPool3d] = Pool[
248 Pool.ADAPTIVEAVG, spatial_dims
249 ]
250
251 block_avgpool = get_avgpool()
252 block_inplanes = [int(x * widen_factor) for x in block_inplanes]
253
254 self.in_planes = block_inplanes[0]
255 self.no_max_pool = no_max_pool
256 self.bias_downsample = bias_downsample
257
258 conv1_kernel_size = ensure_tuple_rep(conv1_t_size, spatial_dims)
259 conv1_stride = ensure_tuple_rep(conv1_t_stride, spatial_dims)
260
261 self.conv1 = conv_type(
262 n_input_channels,
263 self.in_planes,
264 kernel_size=conv1_kernel_size,
265 stride=conv1_stride,
266 padding=tuple(k // 2 for k in conv1_kernel_size),
267 bias=False,
268 )
269
270 norm_layer = get_norm_layer(name=norm, spatial_dims=spatial_dims, channels=self.in_planes)
271 self.bn1 = norm_layer
272 self.act = get_act_layer(name=act)
273 self.maxpool = pool_type(kernel_size=3, stride=2, padding=1)
274 self.layer1 = self._make_layer(block, block_inplanes[0], layers[0], spatial_dims, shortcut_type)

Callers 3

__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45

Calls 6

_make_layerMethod · 0.95
ensure_tuple_repFunction · 0.90
get_norm_layerFunction · 0.90
get_act_layerFunction · 0.90
get_avgpoolFunction · 0.85
as_tensorMethod · 0.80

Tested by

no test coverage detected