PaddlePaddle/PaddleOCR · error · TypeError
Unsupported data type: {pd_dtype}
Error message
Unsupported data type: {pd_dtype} What it means
_pd_dtype_to_np_dtype maps Paddle Inference tensor data types (FLOAT32/INT64/INT32/UINT8/INT8/FLOAT64) to numpy dtypes for building TRT input arrays. Any other Paddle DataType — e.g. FLOAT16, BFLOAT16, BOOL — reaches the else branch and raises TypeError. In practice this means the model contains an input whose precision has no numpy equivalent usable for engine calibration.
Source
Thrown at tools/infer/utility.py:534
pp_model_path = pp_model_file.split(".")[0]
convert(pp_model_path, trt_config)
def _pd_dtype_to_np_dtype(pd_dtype):
if pd_dtype == inference.DataType.FLOAT64:
return np.float64
elif pd_dtype == inference.DataType.FLOAT32:
return np.float32
elif pd_dtype == inference.DataType.INT64:
return np.int64
elif pd_dtype == inference.DataType.INT32:
return np.int32
elif pd_dtype == inference.DataType.UINT8:
return np.uint8
elif pd_dtype == inference.DataType.INT8:
return np.int8
else:
raise TypeError(f"Unsupported data type: {pd_dtype}")
def load_config(file_path):
_, ext = os.path.splitext(file_path)
if ext not in [".yml", ".yaml"]:
raise ValueError(f"only support yaml files for now, got {file_path}")
with open(file_path, "rb") as file:
config = yaml.load(file, Loader=yaml.SafeLoader)
return config
def get_output_tensors(args, mode, predictor):
output_names = predictor.get_output_names()
output_tensors = []
if mode == "rec" and args.rec_algorithm in ["CRNN", "SVTR_LCNet", "SVTR_HGNet"]:
output_name = "softmax_0.tmp_0"
if output_name in output_names:
return [predictor.get_output_handle(output_name)]View on GitHub (pinned to 2661c7c0ef)
Solutions
- Re-export the inference model in FP32 (remove --fp16/half precision at export time) before TRT conversion
- Extend _pd_dtype_to_np_dtype with the needed mapping (e.g. FLOAT16 -> np.float16) if the data is representable
- Skip TensorRT and run plain GPU Paddle Inference for this model
Example fix
# tools/infer/utility.py — before
else:
raise TypeError(f"Unsupported data type: {pd_dtype}")
# after
elif pd_dtype == inference.DataType.FLOAT16:
return np.float16
else:
raise TypeError(f"Unsupported data type: {pd_dtype}") Defensive patterns
Strategy: validation
Validate before calling
SUPPORTED = {inference.DataType.FLOAT64, inference.DataType.FLOAT32,
inference.DataType.INT64, inference.DataType.INT32,
inference.DataType.UINT8, inference.DataType.INT8}
for name in predictor.get_input_names():
t = predictor.get_input_handle(name).type()
assert t in SUPPORTED, f'input {name} has dtype {t}, not usable for TRT build — export FP32' Type guard
def dtype_supported(handle) -> bool:
return handle.type() in {
inference.DataType.FLOAT64, inference.DataType.FLOAT32,
inference.DataType.INT64, inference.DataType.INT32,
inference.DataType.UINT8, inference.DataType.INT8,
} Try / catch
try:
_pd_dtype_to_np_dtype(handle.type())
except TypeError:
raise SystemExit(f'input {name} dtype {handle.type()} unsupported for TRT — re-export model in FP32') Prevention
- Export inference models in FP32 when TensorRT is part of the deployment
- Let TRT do FP16 internally via precision flags rather than exporting FP16 weights
When it happens
Trigger: Loading a model with a FLOAT16/BF16/BOOL input while building TensorRT engines with dynamic shapes; TRT cache regeneration on a model exported at half precision.
Common situations: FP16-exported inference models used with --use_tensorrt; new Paddle versions exposing additional DataType enum values; mixed-precision exports of newer architectures.
Related errors
- Configuration Error: 'trt_dynamic_shapes' must be defined in
- Invalid input name {repr(name)} found in `dynamic_shapes`
- Input name {repr(name)} not found in `dynamic_shapes`
- Invalid input name {repr(name)} found in `dynamic_shape_inpu
AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14).
Data as JSON: /api/errors/a88cca9fb9693e82.
Report an issue: GitHub.