torchserve使用-Torch Model archiver for TorchServe(四)
https://github.com/pytorch/serve/tree/v0.2.0/model-archiver#creating-a-model-archivetorchserve --help查看使用方式:torch-model-archiver -h有效的型号名称必须以字母开头,并且只能包含字母,数字,下划线_,破折号-和句点.。当使用Register Model API注册模型时,可
https://github.com/pytorch/serve/tree/v0.2.0/model-archiver#creating-a-model-archive
torchserve --help
查看使用方式:
torch-model-archiver -h
有效的型号名称必须以字母开头,并且只能包含字母,数字,下划线_,破折号-和句点.。当使用Register Model API注册模型时,可以覆盖模型名称。
模型文件:
模型文件应包含模型架构。在eager模式下,此文件是必需的。
序列化文件:
如果使用torchscript,则序列化文件(.pt或.pth)应该是checkpoint,如果使用eager模式,则应该是state_dict。
模型打包:
For torchscript:
torch-model-archiver --model-name densenet_161 --version 1.0 --serialized-file model.pt --handler image_classifier
For eagermode:
torch-model-archiver --model-name densenet_161 --version 1.0 --model-file model.py --serialized-file model.pt --handler image_classifier
这会将所有模型工件文件打包并输出densenet_161.mar到当前工作目录中。该.mar文件是运行TorchServe所需的全部文件,为简单的图像识别API提供推理请求。

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。
更多推荐
所有评论(0)