PaddlePaddle/PaddleOCR · error · ValueError
Invalid input name {repr(name)} found in `dynamic_shapes`
Error message
Invalid input name {repr(name)} found in `dynamic_shapes` What it means
During _convert_trt (building TensorRT engines from the Paddle model), the code cross-checks the keys of the dynamic_shapes dict against predictor.get_input_names(). This ValueError fires when dynamic_shapes contains an input name the model does not have — a stale or hand-edited shape spec left over from a different model. The check runs before any engine building, so no work is wasted.
Source
Thrown at tools/infer/utility.py:474
), f"The `{type(trt_config)}` don't have the attribute `{attr_name}`!"
setattr(trt_config, attr_name, trt_cfg_setting[attr_name])
def _get_predictor(model_file, params_file):
# HACK
config = inference.Config(str(model_file), str(params_file))
config.enable_use_gpu(100, device_id)
# NOTE: Disable oneDNN to circumvent a bug in Paddle Inference
config.disable_mkldnn()
config.disable_glog_info()
return inference.create_predictor(config)
dynamic_shape_input_data = dynamic_shape_input_data or {}
predictor = _get_predictor(pp_model_file, pp_params_file)
input_names = predictor.get_input_names()
for name in dynamic_shapes:
if name not in input_names:
raise ValueError(
f"Invalid input name {repr(name)} found in `dynamic_shapes`"
)
for name in input_names:
if name not in dynamic_shapes:
raise ValueError(f"Input name {repr(name)} not found in `dynamic_shapes`")
for name in dynamic_shape_input_data:
if name not in input_names:
raise ValueError(
f"Invalid input name {repr(name)} found in `dynamic_shape_input_data`"
)
trt_inputs = []
for name, candidate_shapes in dynamic_shapes.items():
# XXX: Currently we have no way to get the data type of the tensor
# without creating an input handle.
handle = predictor.get_input_handle(name)
dtype = _pd_dtype_to_np_dtype(handle.type())
min_shape, opt_shape, max_shape = candidate_shapesView on GitHub (pinned to 2661c7c0ef)
Solutions
- Inspect actual input names: print(predictor.get_input_names()) or use paddle_infer to list them
- Fix the dynamic_shapes keys (usually in inference.yml Hpi.backend_configs.paddle_infer.trt_dynamic_shapes) to exactly match the model inputs
- Re-download the matching model package so yml and model agree
Example fix
# inference.yml — before trt_dynamic_shapes: x: [[1,3,48,320],[1,3,48,640],[1,3,48,1280]] # model input is 'images' # after trt_dynamic_shapes: images: [[1,3,48,320],[1,3,48,640],[1,3,48,1280]]
Defensive patterns
Strategy: validation
Validate before calling
predictor = build_raw_predictor(model) # or read yml + model once
input_names = set(predictor.get_input_names())
assert set(dynamic_shapes) <= input_names, f'dynamic_shapes keys not in {input_names}' Try / catch
try:
_convert_trt(dynamic_shapes, model_file, params_file, ...)
except ValueError as e:
if 'Invalid input name' in str(e):
raise SystemExit('dynamic_shapes keys must equal predictor.get_input_names()')
raise Prevention
- Generate TRT shape configs from the live model's get_input_names() rather than hand-copying them
- Never reuse an inference.yml across different architectures
When it happens
Trigger: Passing dynamic_shapes={'x': ...} to a model whose input is named 'images' (or vice versa); reusing an inference.yml from one architecture with another model.
Common situations: Copying TRT config between det and rec models whose input tensor names differ; older/newer exports renaming inputs; hand-written shape dictionaries using guessed names.
Related errors
- Input name {repr(name)} not found in `dynamic_shapes`
- Invalid input name {repr(name)} found in `dynamic_shape_inpu
- Configuration Error: 'trt_dynamic_shapes' must be defined in
- Unsupported data type: {pd_dtype}
AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14).
Data as JSON: /api/errors/afd6fb9ce975d4f5.
Report an issue: GitHub.