当前位置:网站首页>004. Torchserve calls LR two category prediction

004. Torchserve calls LR two category prediction

2022-06-13 12:11:00 nsq1101

Preface

Pytorch Within the framework of ,LR Model II classification prediction

Model code reference Logistic Return to ( Achieve two categories )

One 、 The overall steps

1、 Run the code in the blog , Save the model

model_script = torch.jit.script(model)
model_script.save('/Users/serve/model-archiver/LR_scr.pt')

2、 To mar Format

"""
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、 function 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、 Registration model

"""
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、 forecast

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

"""

Two 、 summary

1、Pytorch Run a model under the framework , Save as pt Format
2、 The way of data preprocessing , To mar Format , stay handler.py According to the input data , Format transformation
3、 Display of output results

原网站

版权声明
本文为[nsq1101]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/164/202206131205314540.html