Skip to content
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

Toward Devkit Consistency #10150

Merged
merged 5 commits into from
Jun 14, 2023
Merged

Toward Devkit Consistency #10150

merged 5 commits into from
Jun 14, 2023

Conversation

Bobholamovic
Copy link
Member

@Bobholamovic Bobholamovic commented Jun 13, 2023

目标

修改代码以提升PaddleCV套件一致性,同时适配X项目。修改后,套件应满足如下一致性要求:

  1. 将训练过程中最优(一般是验证集上精度最高)的模型权重存储在输出目录的best_model子目录中,文件命名为model.pdparams。与之相配套的优化器参数(如果存储的话)文件命名为model.pdopt,也存储在该目录中。
  2. 支持将训练、验证过程中VisualDL产生的.log格式日志文件保存在输出目录中(无嵌套子目录)。
  3. 套件根目录存在requirements.txt文件,指定使用套件基础功能需要的依赖。在套件根目录可通过pip install .pip install -e .方式(至少其中一种)安装套件核心库。
  4. 对于模型导出功能,默认支持或通过命令行选项/配置文件等手段支持导出为FD格式。『FD格式』的导出结果通常包含如下文件:
  • inference.pdiparams:保存权重参数。
  • inference.pdiparams.info:保存与参数有关的额外信息。
  • inference.pdmodel:保存模型结构描述信息。
  • (可选)inference.yml:预处理配置文件。

代码变动

  1. 【一致性提升】使训练时检查点存储位置满足一致性要求1。
  2. 【一致性提升】【不兼容升级】修改VisualDL日志存储位置以满足一致性要求2。
  3. 【功能增强】修改tools/infer_det.pyraw_det_res对『零目标框』情形的处理逻辑,在该情形下仍然存储图像(存的是原图),从而使用户在各种情况下均能获得输出图像,而无需关注目标框数量。
  4. 【功能增强】调整signal handlers的设置时机。修改前,signal handlers在每次载入ppocr.data时自动设置,但这种做法有以下缺点:1) 用户在使用Python REPL或进行断点调试时经常需要输入Ctrl+C,而这将直接触发程序的终止,令用户感到疑惑和不便;2) 从调用关系的角度来看,作为callee,逻辑上来说应当尽可能减少对caller的影响,而目前的实现显然不满足这一点;3) 如果库在子进程中被调用,作为子进程,即使不考虑权限问题,只从资源回收的角度来看,试图通过SIGKILL杀死包括父进程以及其它旁支进程在内的整个进程组内的成员仍是危险的行为。修改后,signal handlers只在当前进程为进程组leader、且用户通过脚本执行(排除了REPL的情况)的情况下被设置。此做法仍有优化空间,详见ppocr/data/__init__.py中的注释。

遗留问题

  1. 对于代码变动1和2,尚未更新相关文档。若此PR合入,可能需要套件同学进行更新。
  2. 考虑到反向兼容性,本次改动未对PaddleOCR原本的最优模型存储机制进行变更,而只是追加了best_model目录。因此,输出目录中将存在model.pdparamsmodel.pdopt的两份拷贝。后续需考虑渐进地改动旧的存储机制,使最优模型只保留一份。

@paddle-bot
Copy link

paddle-bot bot commented Jun 13, 2023

Thanks for your contribution!

tink2123
tink2123 previously approved these changes Jun 13, 2023
Copy link
Collaborator

@tink2123 tink2123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

if prefix == 'best_accuracy':
uapi_best_model_path = os.path.join(uapi_best_model_path, 'model')
paddle.save(model.state_dict(), uapi_best_model_path + ".pdparams")

Copy link
Collaborator

@tink2123 tink2123 Jun 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是否也需要保存一份 model.pdopt ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里漏写了,已修改~

Copy link
Collaborator

@tink2123 tink2123 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@tink2123 tink2123 merged commit 2d44a71 into PaddlePaddle:dygraph Jun 14, 2023
2 checks passed
@Bobholamovic Bobholamovic deleted the paddlex branch June 14, 2023 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants