{"record":{"id":"42b8c8d98987abd2","repo":"WZMIAOMIAO/deep-learning-for-image-processing","slug":"the-inverted-residual-setting-should-not-be-empty-42b8c8","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_segmentation/lraspp/src/mobilenet_backbone.py","lineNumber":159,"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":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/WZMIAOMIAO/deep-learning-for-image-processing/blob/1ec3fe6f374fc9969973a61f819de25658595afa/pytorch_segmentation/lraspp/src/mobilenet_backbone.py#L141-L177","documentation":"MobileNetV3.__init__ requires a non-empty inverted_residual_setting list of block configs. An empty list (or None) fails the truthiness check and raises this ValueError, because the model would have no feature extractor layers at all.","triggerScenarios":"`MobileNetV3(inverted_residual_setting=[], num_classes=...)`; passing None without a block preset; programmatically filtering the config list to empty (e.g. selecting only blocks with width >= X); calling with the wrong kwarg so the default list is never built.","commonSituations":"Writing custom model builders that generate configs dynamically and produce an empty list on some condition; forgetting to call the convenience constructors `mobilenet_v3_large/small` that build the config list; refactoring where the default kwarg was removed.","solutions":["Pass a non-empty list of InvertedResidualConfig, or use `mobilenet_v3_large()`/`mobilenet_v3_small()` helpers which construct it","Fix the config-generation logic so it yields at least one block","Add a fallback to the standard bneck_cfg presets when your list is empty"],"exampleFix":"// before\nmodel = MobileNetV3(inverted_residual_setting=[], num_classes=21)  # ValueError\n// after\nmodel = mobilenet_v3_large(num_classes=21)\n# or pass the standard preset:\nmodel = MobileNetV3(inverted_residual_setting=bneck_cfg, num_classes=21)","handlingStrategy":"validation","validationCode":"cfgs = build_inverted_residual_setting(...)\nassert isinstance(cfgs, list) and len(cfgs) > 0, \"config list must be non-empty\"","typeGuard":"def usable_setting(cfgs):\n    return bool(cfgs) and isinstance(cfgs, list)","tryCatchPattern":"try:\n    model = MobileNetV3(inverted_residual_setting=cfgs, num_classes=nc)\nexcept ValueError:\n    logging.warning(\"empty setting; falling back to mobilenet_v3_large preset\")\n    model = mobilenet_v3_large(num_classes=nc)","preventionTips":["Prefer mobilenet_v3_large/small factory functions over manual config lists","Guard config-generation filters so they cannot produce empty lists","Default to the standard bneck_cfg preset","Log the config list length before building the model"],"tags":["python","value-error","mobilenet","empty-list","backbone"],"backgroundTag":"invalid-argument-value","analyzedSha":"1ec3fe6f374fc9969973a61f819de25658595afa","analyzedAt":"2026-08-30T09:19:11.901Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}