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

模型预加载 #517

Closed
BronyaKaslana06 opened this issue Sep 1, 2024 · 4 comments
Closed

模型预加载 #517

BronyaKaslana06 opened this issue Sep 1, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@BronyaKaslana06
Copy link

在我连续处理多个pdf时,我希望能只用加载一次模型,也就是说需要向用户提供一个api接口,方便用户在合适的时机将模型加载到显存中。

@BronyaKaslana06 BronyaKaslana06 added the enhancement New feature or request label Sep 1, 2024
@Jalen-Zhong
Copy link

把模型提出来先加载,再传入函数

@myhloli
Copy link
Collaborator

myhloli commented Sep 2, 2024

可以通过以下代码预加载模型

def init_model():
    from magic_pdf.model.doc_analyze_by_custom_model import ModelSingleton
    try:
        model_manager = ModelSingleton()
        txt_model = model_manager.get_model(False, False)
        logger.info(f"txt_model init final")
        ocr_model = model_manager.get_model(True, False)
        logger.info(f"ocr_model init final")
        return 0
    except Exception as e:
        logger.exception(e)
        return -1


model_init = init_model()
logger.info(f"model_init: {model_init}")

@BronyaKaslana06
Copy link
Author

收到,谢谢大佬们

@myhloli myhloli closed this as completed Sep 3, 2024
@sunnyhwang
Copy link

可以通过以下代码预加载模型

def init_model():
    from magic_pdf.model.doc_analyze_by_custom_model import ModelSingleton
    try:
        model_manager = ModelSingleton()
        txt_model = model_manager.get_model(False, False)
        logger.info(f"txt_model init final")
        ocr_model = model_manager.get_model(True, False)
        logger.info(f"ocr_model init final")
        return 0
    except Exception as e:
        logger.exception(e)
        return -1


model_init = init_model()
logger.info(f"model_init: {model_init}")

感谢提供的代码,方便了很多。但是在使用过程中我发现如果程序出错或者提前结束的情况下,预载的模型还是会留在显存中不会自己结束进程,需要自己手动杀掉才能释放内存。请问这种情况有解决方式吗?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants