opendatalab/MinerU · error · ValueError
PPLCNetV4 only supports 3 input channels, got {in_channels}.
Error message
PPLCNetV4 only supports 3 input channels, got {in_channels}. What it means
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.
Source
Thrown at mineru/model/utils/pytorchocr/modeling/backbones/rec_lcnetv4.py:291
def forward(self, pixel_values):
"""返回四个 stage 的输出特征,供 det/rec 上层按需使用。"""
hidden_states = self.convolution(pixel_values)
feature_maps = []
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:View on GitHub (pinned to 4fe4bde114)
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.
Example fix
# before PPLCNetV4(det=False, in_channels=1) # after img = cv2.cvtColor(gray_img, cv2.COLOR_GRAY2BGR) PPLCNetV4(det=False) # default in_channels=3
Defensive patterns
Strategy: validation
Validate before calling
assert in_channels == 3, "PPLCNetV4 requires 3-channel RGB input; convert grayscale images before the model"
Prevention
- Standardize preprocessing to output 3-channel BGR/RGB
- Remove in_channels overrides inherited from other backbone configs
When it happens
Trigger: 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.
Common situations: Adapting a document pipeline that pre-converts images to grayscale; merging configs from a different backbone that supported 1-channel input.
Related errors
- Unsupported activation: {name}
- PPLCNetV4 {mode} model_size must be one of {list(config_dict
- mode[{model_name}_model] is not implemented!
- mode[{model_name}_model] is not implemented!
- The function 'replace_sub()' is deprecated, please use 'upgr
AI-assisted analysis of opendatalab/MinerU@4fe4bde114 (2026-08-14).
Data as JSON: /api/errors/42388d074b6c9b95.
Report an issue: GitHub.