{"record":{"id":"891246e72b924a8a","repo":"WZMIAOMIAO/deep-learning-for-image-processing","slug":"the-inverted-residual-setting-should-be-list-inver","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_classification/Test6_mobilenet/model_v3.py","lineNumber":155,"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":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/WZMIAOMIAO/deep-learning-for-image-processing/blob/1ec3fe6f374fc9969973a61f819de25658595afa/pytorch_classification/Test6_mobilenet/model_v3.py#L137-L173","documentation":"MobileNetV3.__init__ raises TypeError when inverted_residual_setting is non-empty but is not a List whose elements are all InvertedResidualConfig instances. This guards against passing dicts, tuples, or plain ints/strings as the block specification.","triggerScenarios":"Passing a list of dicts (e.g. JSON-loaded architecture), a tuple of InvertedResidualConfig, a single InvertedResidualConfig (not wrapped in a list), or a list containing mixed types to MobileNetV3(inverted_residual_setting=...).","commonSituations":"Serializing architecture configs to JSON for config-driven experiments and passing them back in (dicts don't survive as InvertedResidualConfig); hand-building configs with raw dicts instead of the dataclass.","solutions":["Build each entry with InvertedResidualConfig(...) instead of plain dicts and pass the list as-is.","Wrap a single InvertedResidualConfig in a list: [cfg].","If configs come from JSON, deserialize each item into InvertedResidualConfig(**d).","Prefer the MobileNetV3Large/MobileNetV3Small helpers, which construct valid configs internally."],"exampleFix":"// before\nmodel = MobileNetV3(inverted_residual_setting=[{\"input_c\": 16, \"kernel\": 3, ...}], num_classes=5)\n// after\ncfg = InvertedResidualConfig(16, 3, 16, 16, True, \"RE\", 1, 1, 1)\nmodel = MobileNetV3(inverted_residual_setting=[cfg], num_classes=5)","handlingStrategy":"type-guard","validationCode":"ok = isinstance(inverted_residual_setting, list) and all(isinstance(s, InvertedResidualConfig) for s in inverted_residual_setting)\nassert ok, \"inverted_residual_setting must be List[InvertedResidualConfig]\"","typeGuard":"def is_block_config_list(x) -> bool:\n    return isinstance(x, list) and all(isinstance(i, InvertedResidualConfig) for i in x)","tryCatchPattern":"try:\n    model = MobileNetV3(inverted_residual_setting=setting, num_classes=n)\nexcept TypeError as e:\n    if \"List[InvertedResidualConfig]\" in str(e):\n        setting = [InvertedResidualConfig(**d) for d in setting]\n        model = MobileNetV3(inverted_residual_setting=setting, num_classes=n)\n    else:\n        raise","preventionTips":["Construct entries with InvertedResidualConfig, never raw dicts.","Re-hydrate JSON configs into dataclass instances before model construction.","Add a type check unit test for custom architecture configs."],"tags":["pytorch","mobilenetv3","typeerror","config"],"backgroundTag":"invalid-model-config-type","analyzedSha":"1ec3fe6f374fc9969973a61f819de25658595afa","analyzedAt":"2026-08-30T09:19:11.901Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}