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、输出结果的展示



