{"record":{"id":"76de692ec8db22ca","repo":"WZMIAOMIAO/deep-learning-for-image-processing","slug":"the-inverted-residual-setting-should-be-list-inver-76de69","errorCode":null,"errorMessage":"The inverted_residual_setting should be List[InvertedResidualConfig]","messagePattern":"The inverted_residual_setting should be List\\[InvertedResidualConfig\\]","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pytorch_segmentation/lraspp/src/mobilenet_backbone.py","lineNumber":162,"sourceCode":"            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,\n                                       norm_layer=norm_layer,\n                                       activation_layer=nn.Hardswish))\n        # building inverted residual blocks","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/WZMIAOMIAO/deep-learning-for-image-processing/blob/1ec3fe6f374fc9969973a61f819de25658595afa/pytorch_segmentation/lraspp/src/mobilenet_backbone.py#L144-L180","documentation":"After the emptiness check, MobileNetV3 validates that inverted_residual_setting is a List whose every element is an InvertedResidualConfig instance. Violating either condition raises this TypeError. This prevents subtle runtime crashes deep in block construction.","triggerScenarios":"Passing a dict/tuple instead of a list (e.g. an OrderedDict of configs); passing plain dicts parsed from YAML/JSON without converting to InvertedResidualConfig; passing a single config object instead of a list; numpy/py3.8 typing quirks where typing.List check fails — code uses `List` from typing via isinstance which requires bare list.","commonSituations":"Config-driven model factories reading architecture specs from files; developers passing tuples copied from older code; hand-written presets using dicts with matching keys but no InvertedResidualConfig class; mixing torchvision's MobileNetV3 (which uses its own internal config class) with this repo's class.","solutions":["Convert each spec dict into `InvertedResidualConfig(**spec)` and collect into a plain `list`","Ensure you use this repo's InvertedResidualConfig class, not torchvision's, so isinstance passes","Pass a `list`, not tuple/dict, and pass the whole list not a single element"],"exampleFix":"// before\nmodel = MobileNetV3(inverted_residual_setting=[{...cfg dict...}], num_classes=21)  # TypeError\n// after\ncfgs = [InvertedResidualConfig(**d) for d in cfg_dicts]\nmodel = MobileNetV3(inverted_residual_setting=cfgs, num_classes=21)","handlingStrategy":"type-guard","validationCode":"assert isinstance(cfgs, list) and all(isinstance(c, InvertedResidualConfig) for c in cfgs), \\\n    \"need List[InvertedResidualConfig] (this repo's class)\"","typeGuard":"def is_valid_setting(cfgs):\n    from typing import List\n    return isinstance(cfgs, list) and all(isinstance(c, InvertedResidualConfig) for c in cfgs)","tryCatchPattern":"try:\n    model = MobileNetV3(inverted_residual_setting=cfgs, num_classes=nc)\nexcept TypeError:\n    cfgs = [InvertedResidualConfig(**c) if isinstance(c, dict) else c for c in cfgs]\n    model = MobileNetV3(inverted_residual_setting=list(cfgs), num_classes=nc)","preventionTips":["Convert dict specs with InvertedResidualConfig(**d) before use","Pass a plain list, not tuple/dict/single object","Never mix torchvision's config class with this repo's MobileNetV3","Add the isinstance check at the top of any config-loading helper"],"tags":["python","type-error","mobilenet","backbone","config"],"backgroundTag":"invalid-argument-type","analyzedSha":"1ec3fe6f374fc9969973a61f819de25658595afa","analyzedAt":"2026-08-30T09:19:11.901Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}