WZMIAOMIAO/deep-learning-for-image-processing · error · TypeError
The inverted_residual_setting should be List[InvertedResidua
Error message
The inverted_residual_setting should be List[InvertedResidualConfig]
What it means
Besides being non-empty, inverted_residual_setting must be a List whose every element is an InvertedResidualConfig. Otherwise the model cannot safely read each block's fields, so __init__ raises TypeError naming the expected type.
Source
Thrown at pytorch_segmentation/deeplab_v3/src/mobilenet_backbone.py:162
result += x
return result
class MobileNetV3(nn.Module):
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):
super(MobileNetV3, self).__init__()
if not inverted_residual_setting:
raise ValueError("The inverted_residual_setting should not be empty.")
elif not (isinstance(inverted_residual_setting, List) 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_c = inverted_residual_setting[0].input_c
layers.append(ConvBNActivation(3,
firstconv_output_c,
kernel_size=3,
stride=2,
norm_layer=norm_layer,
activation_layer=nn.Hardswish))
# building inverted residual blocksView on GitHub (pinned to 1ec3fe6f37)
Solutions
- Convert each entry to InvertedResidualConfig with the right field order/values.
- Use the repo's factory functions (mobilev3_large_150 / mobilev3_small_100) instead of hand-built lists.
- If you have dicts, map them: [InvertedResidualConfig(**d) for d in settings] after verifying fields.
Example fix
// before
settings = [{"input_c": 16, "kernel": 3, "expanded_c": 64, ...}]
model = MobileNetV3(inverted_residual_setting=settings)
// after
settings = [InvertedResidualConfig(16, 3, 16, 16, False, "RE", 1, 1, 1)]
model = MobileNetV3(inverted_residual_setting=settings) Defensive patterns
Strategy: type-guard
Validate before calling
from src.mobilenet_backbone import InvertedResidualConfig assert isinstance(settings, list) and all(isinstance(s, InvertedResidualConfig) for s in settings)
Type guard
from src.mobilenet_backbone import InvertedResidualConfig
def is_valid_settings(settings) -> bool:
return isinstance(settings, list) and all(isinstance(s, InvertedResidualConfig) for s in settings) Try / catch
try:
model = MobileNetV3(inverted_residual_setting=settings, num_classes=n)
except TypeError as e:
logging.error(f"{e}; types={[type(s).__name__ for s in settings]}"); raise Prevention
- Convert dict configs with InvertedResidualConfig(**d)
- Do not mix torchvision MobileNetV3 configs with this repo's class
- Prefer the repo's preset builder functions
When it happens
Trigger: Passing inverted_residual_setting as a tuple, dict, or a list of plain dicts/dataclass-like objects that are not InvertedResidualConfig instances.
Common situations: Building block configs as raw dicts instead of InvertedResidualConfig; mixing configs copied from torchvision's MobileNetV3 (different dataclass) with this repo's implementation; JSON-loaded configs.
Related errors
- illegal stride value.
- The inverted_residual_setting should not be empty.
- The inverted_residual_setting should be List[InvertedResidua
- illegal stride value.
- sampler should be an instance of torch.utils.data.Sampler, b
AI-assisted analysis of WZMIAOMIAO/deep-learning-for-image-processing@1ec3fe6f37 (2026-08-30).
Data as JSON: /api/errors/df740a1b7562c0c8.
Report an issue: GitHub.