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

Method __init__

monai/networks/nets/efficientnet.py:567–620  ·  view source on GitHub ↗

Initialize EfficientNet-B0 to EfficientNet-B7 models as a backbone, the backbone can be used as an encoder for segmentation and objection models. Compared with the class `EfficientNetBN`, the only different place is the forward function. This class refers to `PyTorc

(
        self,
        model_name: str,
        pretrained: bool = True,
        progress: bool = True,
        spatial_dims: int = 2,
        in_channels: int = 3,
        num_classes: int = 1000,
        norm: str | tuple = ("batch", {"eps": 1e-3, "momentum": 0.01}),
        adv_prop: bool = False,
    )

Source from the content-addressed store, hash-verified

565class EfficientNetBNFeatures(EfficientNet):
566
567 def __init__(
568 self,
569 model_name: str,
570 pretrained: bool = True,
571 progress: bool = True,
572 spatial_dims: int = 2,
573 in_channels: int = 3,
574 num_classes: int = 1000,
575 norm: str | tuple = ("batch", {"eps": 1e-3, "momentum": 0.01}),
576 adv_prop: bool = False,
577 ) -> None:
578 """
579 Initialize EfficientNet-B0 to EfficientNet-B7 models as a backbone, the backbone can
580 be used as an encoder for segmentation and objection models.
581 Compared with the class `EfficientNetBN`, the only different place is the forward function.
582
583 This class refers to `PyTorch image models <https://github.com/rwightman/pytorch-image-models>`_.
584
585 """
586 blocks_args_str = [
587 "r1_k3_s11_e1_i32_o16_se0.25",
588 "r2_k3_s22_e6_i16_o24_se0.25",
589 "r2_k5_s22_e6_i24_o40_se0.25",
590 "r3_k3_s22_e6_i40_o80_se0.25",
591 "r3_k5_s11_e6_i80_o112_se0.25",
592 "r4_k5_s22_e6_i112_o192_se0.25",
593 "r1_k3_s11_e6_i192_o320_se0.25",
594 ]
595
596 # check if model_name is valid model
597 if model_name not in efficientnet_params:
598 model_name_string = ", ".join(efficientnet_params.keys())
599 raise ValueError(f"invalid model_name {model_name} found, must be one of {model_name_string} ")
600
601 # get network parameters
602 weight_coeff, depth_coeff, image_size, dropout_rate, dropconnect_rate = efficientnet_params[model_name]
603
604 # create model and initialize random weights
605 super().__init__(
606 blocks_args_str=blocks_args_str,
607 spatial_dims=spatial_dims,
608 in_channels=in_channels,
609 num_classes=num_classes,
610 width_coefficient=weight_coeff,
611 depth_coefficient=depth_coeff,
612 dropout_rate=dropout_rate,
613 image_size=image_size,
614 drop_connect_rate=dropconnect_rate,
615 norm=norm,
616 )
617
618 # only pretrained for when `spatial_dims` is 2
619 if pretrained and (spatial_dims == 2):
620 _load_state_dict(self, model_name, progress, adv_prop)
621
622 def forward(self, inputs: torch.Tensor):
623 """

Callers

nothing calls this directly

Calls 2

_load_state_dictFunction · 0.70
__init__Method · 0.45

Tested by

no test coverage detected