Skip to content

🔧 修复版面分析JSON序列化numpy类型兼容性问题 #4396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: release/3.1
Choose a base branch
from

Conversation

hwb96
Copy link

@hwb96 hwb96 commented Jul 26, 2025

📝 变更说明

修复了PaddleX版面分析结果JSON序列化时numpy类型不兼容的问题。

🔗 关联Issue

Fixes #4395

🛠️ 主要变更

  • _format_data 函数中添加了对 np.int32, np.int64, np.float32, np.float64 类型的支持
  • 扩展了现有的numpy类型处理逻辑
  • 确保与numpy 2.0+版本的兼容性

✅ 测试

  • 本地测试通过
  • 版面分析结果可以正常序列化为JSON
  • 兼容numpy 1.26.4和2.0.2+版本

📋 检查清单

  • 代码符合项目规范
  • 添加了必要的测试
  • 更新了相关文档
  • 通过了所有现有测试

🔍 技术细节

修复了 paddlex/inference/common/result/mixin.py_format_data 函数对numpy类型的处理:

if isinstance(obj, (np.float32, np.float64)):
    return float(obj)
elif isinstance(obj, (np.int32, np.int64)):
    return int(obj)

这样可以确保所有常见的numpy数值类型都能正确序列化为JSON。

修复 _format_data 函数未处理 numpy 整数类型(np.int32, np.int64)的问题,
防止 OCR 结果中包含 numpy 整数坐标时出现 JSON 序列化错误。

修复内容:
- 添加对 np.int32 和 np.int64 类型的支持
- 将 numpy 整数转换为 Python 原生 int 类型
- 扩展 np.float64 支持以保持类型处理一致性

Fixes JSON serialization errors when OCR results contain numpy integer coordinates.

🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored- Claude <[email protected]>
Copy link

paddle-bot bot commented Jul 26, 2025

Thanks for your contribution!

@CLAassistant
Copy link

CLAassistant commented Jul 26, 2025

CLA assistant check
All committers have signed the CLA.

@paddle-bot paddle-bot bot added the contributor External developers label Jul 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 PaddleX版面分析结果JSON序列化失败 - numpy类型兼容性问题
2 participants