WZMIAOMIAO/deep-learning-for-image-processing · error · ValueError
The inverted_residual_setting should not be empty.
Error message
The inverted_residual_setting should not be empty.
What it means
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.
Source
Thrown at pytorch_segmentation/lraspp/src/mobilenet_backbone.py:159
def forward(self, x: Tensor) -> Tensor:
result = self.block(x)
if self.use_res_connect:
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,View on GitHub (pinned to 1ec3fe6f37)
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
Example fix
// before model = MobileNetV3(inverted_residual_setting=[], num_classes=21) # ValueError // after model = mobilenet_v3_large(num_classes=21) # or pass the standard preset: model = MobileNetV3(inverted_residual_setting=bneck_cfg, num_classes=21)
Defensive patterns
Strategy: validation
Validate before calling
cfgs = build_inverted_residual_setting(...) assert isinstance(cfgs, list) and len(cfgs) > 0, "config list must be non-empty"
Type guard
def usable_setting(cfgs):
return bool(cfgs) and isinstance(cfgs, list) Try / catch
try:
model = MobileNetV3(inverted_residual_setting=cfgs, num_classes=nc)
except ValueError:
logging.warning("empty setting; falling back to mobilenet_v3_large preset")
model = mobilenet_v3_large(num_classes=nc) Prevention
- 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
When it happens
Trigger: `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.
Common situations: 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.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- illegal stride value.
- return_layers are not present in model
- return_layers are not present in model
- The inverted_residual_setting should be List[InvertedResidua
- return_layers are not present in model
AI-assisted analysis of WZMIAOMIAO/deep-learning-for-image-processing@1ec3fe6f37 (2026-08-30).
Data as JSON: /api/errors/42b8c8d98987abd2.
Report an issue: GitHub.