{"record":{"id":"5fb64f9c8d981ad4","repo":"WZMIAOMIAO/deep-learning-for-image-processing","slug":"the-inverted-residual-setting-should-not-be-empty","errorCode":null,"errorMessage":"The inverted_residual_setting should not be empty.","messagePattern":"The inverted_residual_setting should not be empty\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pytorch_classification/Test6_mobilenet/model_v3.py","lineNumber":152,"sourceCode":"    def forward(self, x: Tensor) -> Tensor:\n        result = self.block(x)\n        if self.use_res_connect:\n            result += x\n\n        return result\n\n\nclass MobileNetV3(nn.Module):\n    def __init__(self,\n                 inverted_residual_setting: List[InvertedResidualConfig],\n                 last_channel: int,\n                 num_classes: int = 1000,\n                 block: Optional[Callable[..., nn.Module]] = None,\n                 norm_layer: Optional[Callable[..., nn.Module]] = None):\n        super(MobileNetV3, self).__init__()\n\n        if not inverted_residual_setting:\n            raise ValueError(\"The inverted_residual_setting should not be empty.\")\n        elif not (isinstance(inverted_residual_setting, List) and\n                  all([isinstance(s, InvertedResidualConfig) for s in inverted_residual_setting])):\n            raise TypeError(\"The inverted_residual_setting should be List[InvertedResidualConfig]\")\n\n        if block is None:\n            block = InvertedResidual\n\n        if norm_layer is None:\n            norm_layer = partial(nn.BatchNorm2d, eps=0.001, momentum=0.01)\n\n        layers: List[nn.Module] = []\n\n        # building first layer\n        firstconv_output_c = inverted_residual_setting[0].input_c\n        layers.append(ConvBNActivation(3,\n                                       firstconv_output_c,\n                                       kernel_size=3,\n                                       stride=2,","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/WZMIAOMIAO/deep-learning-for-image-processing/blob/1ec3fe6f374fc9969973a61f819de25658595afa/pytorch_classification/Test6_mobilenet/model_v3.py#L134-L170","documentation":"MobileNetV3.__init__ raises ValueError when inverted_residual_setting is falsy (None or an empty list). The block-configuration list defines the entire feature extractor, so constructing the model without it is treated as a programmer error rather than an allowed default.","triggerScenarios":"Calling MobileNetV3() with inverted_residual_setting=None or [] — e.g. forgetting to pass the bneck config list, or passing a variable that failed to populate.","commonSituations":"Instantiating MobileNetV3 directly instead of via the _mobilenet_v3_conf/.MobileNetV3Large or MobileNetV3Small factory helpers that build the standard configs; refactoring code and dropping the argument.","solutions":["Use the provided helpers MobileNetV3Large(num_classes=...) or MobileNetV3Small(num_classes=...) instead of constructing MobileNetV3 directly.","If constructing directly, pass a valid non-empty List[InvertedResidualConfig].","Check that the variable holding your config list isn't accidentally None due to an earlier failed assignment."],"exampleFix":"// before\nmodel = MobileNetV3(inverted_residual_setting=None, num_classes=5)\n// after\nmodel = MobileNetV3Large(num_classes=5)","handlingStrategy":"validation","validationCode":"if not inverted_residual_setting:\n    raise ValueError(\"inverted_residual_setting must be a non-empty list\")\nmodel = MobileNetV3(inverted_residual_setting=inverted_residual_setting, num_classes=num_classes)","typeGuard":"def is_valid_setting(s) -> bool:\n    return isinstance(s, list) and len(s) > 0 and all(isinstance(x, InvertedResidualConfig) for x in s)","tryCatchPattern":"try:\n    model = MobileNetV3(inverted_residual_setting=setting, num_classes=n)\nexcept ValueError as e:\n    if \"should not be empty\" in str(e):\n        model = MobileNetV3Large(num_classes=n)\n    else:\n        raise","preventionTips":["Use MobileNetV3Large/MobileNetV3Small instead of the base class.","Check the config variable is populated before passing it.","Don't pass None positionally."],"tags":["pytorch","mobilenetv3","config","valueerror"],"backgroundTag":"empty-model-config","analyzedSha":"1ec3fe6f374fc9969973a61f819de25658595afa","analyzedAt":"2026-08-30T09:19:11.901Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}