{"record":{"id":"42388d074b6c9b95","repo":"opendatalab/MinerU","slug":"pplcnetv4-only-supports-3-input-channels-got-in","errorCode":null,"errorMessage":"PPLCNetV4 only supports 3 input channels, got {in_channels}.","messagePattern":"PPLCNetV4 only supports 3 input channels, got (.+?)\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mineru/model/utils/pytorchocr/modeling/backbones/rec_lcnetv4.py","lineNumber":291,"sourceCode":"    def forward(self, pixel_values):\n        \"\"\"返回四个 stage 的输出特征，供 det/rec 上层按需使用。\"\"\"\n        hidden_states = self.convolution(pixel_values)\n        feature_maps = []\n        for block in self.blocks:\n            hidden_states = block(hidden_states)\n            feature_maps.append(hidden_states)\n        return feature_maps\n\n\nclass PPLCNetV4(nn.Module):\n    \"\"\"PP-OCRv6 使用的 PPLCNetV4 backbone，支持 det small 和 rec small/medium。\"\"\"\n\n    def __init__(self, det=False, model_size=\"small\", in_channels=3, **kwargs):\n        \"\"\"按 det/rec 模式选择 v6 的固定网络配置。\"\"\"\n        super().__init__()\n        self.det = det\n        if in_channels != 3:\n            raise ValueError(f\"PPLCNetV4 only supports 3 input channels, got {in_channels}.\")\n        config_dict = NET_CONFIG_DET if det else NET_CONFIG_REC\n        if model_size not in config_dict:\n            mode = \"det\" if det else \"rec\"\n            raise ValueError(f\"PPLCNetV4 {mode} model_size must be one of {list(config_dict)}, got {model_size}.\")\n        config = config_dict[model_size]\n        self.encoder = PPLCNetV4Encoder(config[\"stem_channels\"], config[\"block_configs\"])\n        stage_out_channels = [stage[-1][2] for stage in config[\"block_configs\"]]\n        self.out_channels = stage_out_channels if det else stage_out_channels[-1]\n\n    def forward(self, x):\n        \"\"\"det 返回四级特征列表，rec 返回高度池化后的识别特征。\"\"\"\n        feature_maps = self.encoder(x)\n        if self.det:\n            return feature_maps\n        x = feature_maps[-1]\n        if self.training:\n            return F.adaptive_avg_pool2d(x, [1, 40])\n        if x.shape[2] < 3:","sourceCodeStart":273,"sourceCodeEnd":309,"githubUrl":"https://github.com/opendatalab/MinerU/blob/4fe4bde114a23ee5dd637eae99b767f4669bf58c/mineru/model/utils/pytorchocr/modeling/backbones/rec_lcnetv4.py#L273-L309","documentation":"Raised by PPLCNetV4.__init__ when in_channels is anything other than 3. The stem is hard-wired for RGB input, and both the det and rec v6 net configs assume 3-channel images, so grayscale/4-channel input is rejected up front.","triggerScenarios":"Building the PP-OCRv6 backbone with in_channels=1 (grayscale pipeline) or in_channels=4 (RGBA) via config or kwargs; a config key like in_channels: 1 inherited from another model.","commonSituations":"Adapting a document pipeline that pre-converts images to grayscale; merging configs from a different backbone that supported 1-channel input.","solutions":["Convert inputs to 3-channel RGB before the model (cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)) and leave in_channels at the default 3.","Remove an explicit in_channels override from the config so the default is used."],"exampleFix":"# before\nPPLCNetV4(det=False, in_channels=1)\n\n# after\nimg = cv2.cvtColor(gray_img, cv2.COLOR_GRAY2BGR)\nPPLCNetV4(det=False)  # default in_channels=3","handlingStrategy":"validation","validationCode":"assert in_channels == 3, \"PPLCNetV4 requires 3-channel RGB input; convert grayscale images before the model\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Standardize preprocessing to output 3-channel BGR/RGB","Remove in_channels overrides inherited from other backbone configs"],"tags":["ocr","backbone","lcnet","input-channels","valueerror"],"backgroundTag":null,"analyzedSha":"4fe4bde114a23ee5dd637eae99b767f4669bf58c","analyzedAt":"2026-08-14T21:29:18.456Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}