TorchServe生产环境模型部署

本文介绍了如何使用TorchServe在Windows10上部署训练好的目标检测模型,详细阐述了安装过程、模型打包、命令解析、handler文件的编写以及index_to_name.json文件的作用,特别强调了preprocess和postprocess方法的重要性。
摘要由CSDN通过智能技术生成

我们训练好一个目标检测模型,想要部署在生产环境中,查了很多资料,最终选择使用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
  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值