我们训练好一个目标检测模型,想要部署在生产环境中,查了很多资料,最终选择使用TorchServe来部署。TorchServe是AWS和Facebook联合开发的,所以没有多想,选择大厂的东西应该没有错,部署模型过程中踩了很多坑,最终成功在windows10上成功部署,后面会在linux服务器上部署。
1.安装
我电脑上安装的cuda版本为10.1,TorchServe对cuda10.1只支持到pytorch1.8.1或者更高版本。
首先安装依赖:下载serve(https://github.com/pytorch/serve#serve-a-model):
git clone https://github.com/pytorch/serve.git
然后进入serve:
python ./ts_scripts/install_dependencies.py --cuda=cu101
安装torchserve
pip install torchserve torch-model-archiver torch-workflow-archiver
2.命令分析:
打包模型,打包成.mar文件
torch-model-archiver --model-name densenet161
--version 1.0
--model-file ./serve/examples/image_classifier/densenet_161/model.py
--serialized-file densenet161-8d451a50.pth
--export-p