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

Method __init__

monai/networks/nets/resnet.py:369–403  ·  view source on GitHub ↗

Initialize resnet18 to resnet200 models as a backbone, the backbone can be used as an encoder for segmentation and objection models. Compared with the class `ResNet`, the only different place is the forward function. Args: model_name: name of model to initialize

(self, model_name: str, pretrained: bool = True, spatial_dims: int = 3, in_channels: int = 1)

Source from the content-addressed store, hash-verified

367class ResNetFeatures(ResNet):
368
369 def __init__(self, model_name: str, pretrained: bool = True, spatial_dims: int = 3, in_channels: int = 1) -> None:
370 """Initialize resnet18 to resnet200 models as a backbone, the backbone can be used as an encoder for
371 segmentation and objection models.
372
373 Compared with the class `ResNet`, the only different place is the forward function.
374
375 Args:
376 model_name: name of model to initialize, can be from [resnet10, ..., resnet200].
377 pretrained: whether to initialize pretrained MedicalNet weights,
378 only available for spatial_dims=3 and in_channels=1.
379 spatial_dims: number of spatial dimensions of the input image.
380 in_channels: number of input channels for first convolutional layer.
381 """
382 if model_name not in resnet_params:
383 model_name_string = ", ".join(resnet_params.keys())
384 raise ValueError(f"invalid model_name {model_name} found, must be one of {model_name_string} ")
385
386 block, layers, shortcut_type, bias_downsample, datasets23 = resnet_params[model_name]
387
388 super().__init__(
389 block=block,
390 layers=layers,
391 block_inplanes=get_inplanes(),
392 spatial_dims=spatial_dims,
393 n_input_channels=in_channels,
394 conv1_t_stride=2,
395 shortcut_type=shortcut_type,
396 feed_forward=False,
397 bias_downsample=bias_downsample,
398 )
399 if pretrained:
400 if spatial_dims == 3 and in_channels == 1:
401 _load_state_dict(self, model_name, datasets23=datasets23)
402 else:
403 raise ValueError("Pretrained resnet models are only available for in_channels=1 and spatial_dims=3.")
404
405 def forward(self, inputs: torch.Tensor):
406 """

Callers

nothing calls this directly

Calls 3

get_inplanesFunction · 0.85
_load_state_dictFunction · 0.70
__init__Method · 0.45

Tested by

no test coverage detected