Refatoração: Melhorar qualidade de código em export_model.py e save__load.py#16793
Open
Gabriel-Enrico wants to merge 1 commit intoPaddlePaddle:mainfrom
Open
Refatoração: Melhorar qualidade de código em export_model.py e save__load.py#16793Gabriel-Enrico wants to merge 1 commit intoPaddlePaddle:mainfrom
Gabriel-Enrico wants to merge 1 commit intoPaddlePaddle:mainfrom
Conversation
|
Thanks for your contribution! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refatoração: Melhorar qualidade de código em export_model.py e save_load.py
Contexto
Enquanto estudava o código do PaddleOCR, notei que alguns módulos utilitários tinham oportunidades de melhoria. Decidi fazer uma análise estática usando Pylint e Radon para identificar os principais problemas.
O que foi feito
export_model.py
A função dynamic_to_static() estava muito complexa com muitas condições aninhadas. Consegui simplificar bastante:
Também melhorei a documentação e modernizei o código para usar f-strings.
save_load.py
Notei que as funções load_model() e load_pretrained_params() tinham praticamente o mesmo código de carregamento de parâmetros. Extraí isso em _load_and_set_params() para evitar duplicação.
Também organizei melhor a lógica de salvamento separando em _save_nlp_model() e _save_generic_model().
Resultados da Refatoração
Notas Importantes