(
            self,
            inverted_residual_setting: List[InvertedResidualConfig],
            last_channel: int,
            num_classes: int=1000,
            block: Optional[Callable[..., nn.Module]]=None,
            norm_layer: Optional[Callable[..., nn.Module]]=None,
            dropout: float=0.2,
            **kwargs: Any, )
MobileNet V3 main class

        Args:
            inverted_residual_setting (List[InvertedResidualConfig]): Network structure
            last_channel (int): The number of channels on the penultimate layer
            num_classes (int): Number of classes
            block (Optional[Callable[..., nn.Module]]): Module specifying inverted residual building block for mobilenet
            norm_layer (Optional[Callable[..., nn.Module]]): Module specifying the normalization layer to use
            dropout (float): The droupout probability
MobileNet V3 main class
MobileNet V3 main class
def __init__(
            self,
            inverted_residual_setting: List[InvertedResidualConfig],
            last_channel: int,
            num_classes: int=1000,
            block: Optional[Callable[..., nn.Module]]=None,
            norm_layer: Optional[Callable[..., nn.Module]]=None,
            dropout: float=0.2,
            **kwargs: Any, ) -> None:
        """
        MobileNet V3 main class

        Args:
            inverted_residual_setting (List[InvertedResidualConfig]): Network structure
            last_channel (int): The number of channels on the penultimate layer
            num_classes (int): Number of classes
            block (Optional[Callable[..., nn.Module]]): Module specifying inverted residual building block for mobilenet
            norm_layer (Optional[Callable[..., nn.Module]]): Module specifying the normalization layer to use
            dropout (float): The droupout probability
        """
        super().__init__()

        if not inverted_residual_setting:
            raise ValueError(
                "The inverted_residual_setting should not be empty")
        elif not (isinstance(inverted_residual_setting, Sequence) and all([
                isinstance(s, InvertedResidualConfig)
                for s in inverted_residual_setting
        ])):
            raise TypeError(
                "The inverted_residual_setting should be List[InvertedResidualConfig]"
            )

        if block is None:
            block = InvertedResidual

        if norm_layer is None:
            norm_layer = partial(nn.BatchNorm2d, eps=0.001, momentum=0.01)

        layers: List[nn.Module] = []

        # building first layer
        firstconv_output_channels = inverted_residual_setting[0].input_channels
        layers.append(
            ConvNormActivation(
                3,
                firstconv_output_channels,
                kernel_size=3,
                stride=2,
                norm_layer=norm_layer,
                activation_layer=nn.Hardswish, ))

        # building inverted residual blocks
        for cnf in inverted_residual_setting:
            layers.append(block(cnf, norm_layer))

        # building last several layers
        lastconv_input_channels = inverted_residual_setting[-1].out_channels
        lastconv_output_channels = 6 * lastconv_input_channels
        layers.append(
            ConvNormActivation(
                lastconv_input_channels,
                lastconv_output_channels,
                kernel_size=1,
                norm_layer=norm_layer,
                activation_layer=nn.Hardswish, ))

        self.features = nn.Sequential(*layers)
        self.avgpool = nn.AdaptiveAvgPool2d(1)
        self.classifier = nn.Sequential(
            nn.Linear(lastconv_output_channels, last_channel),
            nn.Hardswish(inplace=True),
            nn.Dropout(
                p=dropout, inplace=True),
            nn.Linear(last_channel, num_classes), )

        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                nn.init.kaiming_normal_(m.weight, mode="fan_out")
                if m.bias is not None:
                    nn.init.zeros_(m.bias)
            elif isinstance(m, (nn.BatchNorm2d, nn.GroupNorm)):
                nn.init.ones_(m.weight)
                nn.init.zeros_(m.bias)
            elif isinstance(m, nn.Linear):
                nn.init.normal_(m.weight, 0, 0.01)
                nn.init.zeros_(m.bias)
def __init__ ( self , inverted_residual_setting : List [ InvertedResidualConfig ] , last_channel : int , num_classes : int = 1000 , block : Optional [ Callable [ ... , nn . Module ] ] = None , norm_layer : Optional [ Callable [ ... , nn . Module ] ] = None , dropout : float = 0.2 , * * kwargs : Any , ) -> None : super ( ) . __init__ ( ) if not inverted_residual_setting : raise ValueError ( "The inverted_residual_setting should not be empty" ) elif not ( isinstance ( inverted_residual_setting , Sequence ) and all ( [ isinstance ( s , InvertedResidualConfig ) for s in inverted_residual_setting ] ) ) : raise TypeError ( "The inverted_residual_setting should be List[InvertedResidualConfig]" ) if block is None : block = InvertedResidual if norm_layer is None : norm_layer = partial ( nn . BatchNorm2d , eps = 0.001 , momentum = 0.01 ) layers : List [ nn . Module ] = [ ] # building first layer firstconv_output_channels = inverted_residual_setting [ 0 ] . input_channels layers . append ( ConvNormActivation ( 3 , firstconv_output_channels , kernel_size = 3 , stride = 2 , norm_layer = norm_layer , activation_layer = nn . Hardswish , ) ) # building inverted residual blocks for cnf in inverted_residual_setting : layers . append ( block ( cnf , norm_layer ) ) # building last several layers lastconv_input_channels = inverted_residual_setting [ - 1 ] . out_channels lastconv_output_channels = 6 * lastconv_input_channels layers . append ( ConvNormActivation ( lastconv_input_channels , lastconv_output_channels , kernel_size = 1 , norm_layer = norm_layer , activation_layer = nn . Hardswish , ) ) self . features = nn . Sequential ( * layers ) self . avgpool = nn . AdaptiveAvgPool2d ( 1 ) self . classifier = nn . Sequential ( nn . Linear ( lastconv_output_channels , last_channel ) , nn . Hardswish ( inplace = True ) , nn . Dropout ( p = dropout , inplace = True ) , nn . Linear ( last_channel , num_classes ) , ) for m in self . modules ( ) : if isinstance ( m , nn . Conv2d ) : nn . init . kaiming_normal_ ( m . weight , mode = "fan_out" ) if m . bias is not None : nn . init . zeros_ ( m . bias ) elif isinstance ( m , ( nn . BatchNorm2d , nn . GroupNorm ) ) : nn . init . ones_ ( m . weight ) nn . init . zeros_ ( m . bias ) elif isinstance ( m , nn . Linear ) : nn . init . normal_ ( m . weight , 0 , 0.01 ) nn . init . zeros_ ( m . bias )