栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

004、torchserve 调用LR二分类预测

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

004、torchserve 调用LR二分类预测

前言

Pytorch框架下,LR模型二分类预测

模型代码参考Logistic 回归(实现二分类)

一、总体步骤 1、运行博客中代码,保存模型
model_script = torch.jit.script(model)
model_script.save('/Users/serve/model-archiver/LR_scr.pt')

2、转为mar格式

"""
model-archiver % torch-model-archiver -f --model-name LR_scr --version 1.0 
--serialized-file LR_scr.pt 
--handler /Users/hb/Desktop/sheng/quan/Coding/Test/LRHandler.py 
--export-path model-store/
"""

3、运行docker

"""
docker run --rm -it -p 8080:8080 -p 8081:8081 --name mar -v $(pwd)/model-store:/home/model-server/model-store -v $(pwd)/examples:/home/model-server/examples pytorch/torchserve:latest
"""

4、注册模型

"""
curl --location --request POST 'http://localhost:8081/models' 
--header 'Content-Type: application/json' 
--data-raw '{
"url": "LR_scr.mar",
"batch_size": 64,
"initial_workers": 1
}'

"""

5、预测

"""
curl --location --request POST 'http://localhost:8080/predictions/LR_scr' 
--header 'Content-Type: application/json' 
--data-raw '[4.1]'

"""
二、总结

1、Pytorch 框架下运行一个模型,保存为pt格式
2、数据预处理的方式,转为mar格式,在handler.py 中需要根据输入的数据,进行格式变换
3、输出结果的展示

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/964947.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号