PaddlePaddle/PaddleOCR · error · ValueError
mode can only be one of ['lite', 'large'], but received {}
Error message
mode can only be one of ['lite', 'large'], but received {} What it means
RSEFPN (the DB-detection FPN in db_fpn.py) selects its pan-head convolution type from mode: 'lite' uses depthwise-separable DSConv, 'large' uses full nn.Conv2D. Any other string fails the elif chain and raises this ValueError at construction time.
Source
Thrown at ppocr/modeling/necks/db_fpn.py:449
class LKPAN(nn.Layer):
def __init__(self, in_channels, out_channels, mode="large", **kwargs):
super(LKPAN, self).__init__()
self.out_channels = out_channels
weight_attr = paddle.nn.initializer.KaimingUniform()
self.ins_conv = nn.LayerList()
self.inp_conv = nn.LayerList()
# pan head
self.pan_head_conv = nn.LayerList()
self.pan_lat_conv = nn.LayerList()
if mode.lower() == "lite":
p_layer = DSConv
elif mode.lower() == "large":
p_layer = nn.Conv2D
else:
raise ValueError(
"mode can only be one of ['lite', 'large'], but received {}".format(
mode
)
)
for i in range(len(in_channels)):
self.ins_conv.append(
nn.Conv2D(
in_channels=in_channels[i],
out_channels=self.out_channels,
kernel_size=1,
weight_attr=ParamAttr(initializer=weight_attr),
bias_attr=False,
)
)
self.inp_conv.append(
p_layer(View on GitHub (pinned to 2661c7c0ef)
Solutions
- Set Neck.Mode to "lite" (DSConv, faster/smaller) or "large" (Conv2D, heavier) in the detection config
- Check for stray whitespace/case in the Mode string (' lite'.lower() != 'lite' only if leading space — trim it)
Example fix
# before (config yaml) Neck: name: RSEFPN Mode: 'small' # after Neck: name: RSEFPN Mode: 'lite'
Defensive patterns
Strategy: validation
Validate before calling
mode = str(neck_cfg['Mode']).strip().lower()
assert mode in ('lite', 'large'), f"Mode must be 'lite' or 'large', got {neck_cfg['Mode']!r}" Type guard
def valid_fpn_mode(mode) -> bool:
return isinstance(mode, str) and mode.strip().lower() in ('lite', 'large') Prevention
- Validate config against the allowed mode set before build_model
- Copy mode values from official RSEFPN yamls instead of typing them
When it happens
Trigger: Building a DB/RSE detection model whose Neck config has Mode set to something other than 'lite' or 'large' (case-insensitive), e.g. 'small', 'base', or a typo like 'Lite ' (note: 'LITE'.lower()=='lite' so only exact-after-lower strings pass).
Common situations: Copying a detection yaml and changing Mode to match a backbone scale naming ('tiny'/'base'); older configs that used different mode names; typos in hand-written Neck sections.
Related errors
- embed_dim must be divisible by num_heads (got `embed_dim`: {
- DilatedReparamBlock requires kernel_size in [5,7,9,11,13], b
- Please set inference model dir in Global.inference_model or
- "out_size" must be an integer or tuple of integers
- Sliding window is currently only implemented for causal mask
AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14).
Data as JSON: /api/errors/a3610c54536b0e0d.
Report an issue: GitHub.