opendatalab/MinerU · error · ValueError

PPLCNetV4 {mode} model_size must be one of {list(config_dict

Error message

PPLCNetV4 {mode} model_size must be one of {list(config_dict)}, got {model_size}.

What it means

Raised by PPLCNetV4.__init__ when model_size is not a key of the mode's config table: NET_CONFIG_DET (det mode) or NET_CONFIG_REC (rec mode, typically small/medium). It disambiguates det vs rec in the message so you know which table rejected the value.

Source

Thrown at mineru/model/utils/pytorchocr/modeling/backbones/rec_lcnetv4.py:295

        for block in self.blocks:
            hidden_states = block(hidden_states)
            feature_maps.append(hidden_states)
        return feature_maps


class PPLCNetV4(nn.Module):
    """PP-OCRv6 使用的 PPLCNetV4 backbone,支持 det small 和 rec small/medium。"""

    def __init__(self, det=False, model_size="small", in_channels=3, **kwargs):
        """按 det/rec 模式选择 v6 的固定网络配置。"""
        super().__init__()
        self.det = det
        if in_channels != 3:
            raise ValueError(f"PPLCNetV4 only supports 3 input channels, got {in_channels}.")
        config_dict = NET_CONFIG_DET if det else NET_CONFIG_REC
        if model_size not in config_dict:
            mode = "det" if det else "rec"
            raise ValueError(f"PPLCNetV4 {mode} model_size must be one of {list(config_dict)}, got {model_size}.")
        config = config_dict[model_size]
        self.encoder = PPLCNetV4Encoder(config["stem_channels"], config["block_configs"])
        stage_out_channels = [stage[-1][2] for stage in config["block_configs"]]
        self.out_channels = stage_out_channels if det else stage_out_channels[-1]

    def forward(self, x):
        """det 返回四级特征列表,rec 返回高度池化后的识别特征。"""
        feature_maps = self.encoder(x)
        if self.det:
            return feature_maps
        x = feature_maps[-1]
        if self.training:
            return F.adaptive_avg_pool2d(x, [1, 40])
        if x.shape[2] < 3:
            raise ValueError(f"Feature height {x.shape[2]} < pool kernel 3.")
        return F.avg_pool2d(x, [3, 2])

View on GitHub (pinned to 4fe4bde114)

Solutions

  1. Read the message: it lists the valid sizes for the current det/rec mode — pick one of those.
  2. Use separate model_size settings for the det and rec v6 models.
  3. Check case sensitivity: use lowercase sizes.

Example fix

# before
PPLCNetV4(det=False, model_size="large")

# after
PPLCNetV4(det=False, model_size="medium")
Defensive patterns

Strategy: validation

Validate before calling

valid = list(NET_CONFIG_DET if det else NET_CONFIG_REC)
assert model_size in valid, f"model_size must be one of {valid}, got {model_size!r}"

Prevention

When it happens

Trigger: Constructing the rec backbone with model_size='large' if only small/medium exist for rec; using det-only sizes in rec mode or vice versa; typos like 'Small'.

Common situations: Sharing one model_size across det and rec v6 components; porting configs between det and rec YAMLs; case mismatches.

Related errors


AI-assisted analysis of opendatalab/MinerU@4fe4bde114 (2026-08-14). Data as JSON: /api/errors/f7393e3ea8b4f5e8. Report an issue: GitHub.