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

001、macOS安装torchserve

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

001、macOS安装torchserve

安装步骤

Docker、torchserve安装.
本例只是简单安装、测试torchserve,直接获取模型预测。

1、下载docker

https://docs.docker.com/desktop/mac/install/
官网下载、安装
根据自己mac的芯片选择下载

修改镜像加速

效果如下
https://blog.csdn.net/iulmt/article/details/123326525

最后点击 apply&restart
cmd再检查一下

2、 docker安装torchserve

torchserve官方文档 https://pytorch.org/serve/index.html
docker安装torch serve官方教程:https://github.com/pytorch/serve/blob/master/docker/README.md
官方教程只能参考,有些小坑,需要反复尝试

1、打开cmd
  • git clone https://github.com/pytorch/serve.git

  • cd serve / model-archiver

  • mkdir model-store

2、启动服务、下载torchserve

这里的操作和官方文档不太一样,请注意。

2.1 当前目录下启动空白服务,下载torchserve

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
2.2 重新打开一个cmd
  • 查看安装模型
    curl http://127.0.0.1:8081/models
    若模型为空,需要注册一个模型:
    官方地址 https://pytorch.org/serve/management_api.html#register-a-model
    代码操作
curl -X POST  "http://localhost:8081/models?url=https://torchserve.pytorch.org/mar_files/squeezenet1_1.mar"

成功结果展示:

{
  "status": "Model "squeezenet_v1.1" Version: 1.0 registered with 0 initial workers. Use scale workers API to add workers for the model."
}

下载一个模型,用于后续预测。
这里直接是.mar 格式的模型。一般pytorch模型保存为pt格式,再转为.mar格式。
由于只是安装、测试,所以没有进行这一步。

  • 查看连接是否成功
    curl http://127.0.0.1:8080/ping
3、预测 下载一张图片

curl -O https://s3.amazonaws.com/model-server/inputs/kitten.jpg

预测

curl ‘http://127.0.0.1:8080/predictions/squeezenet1_1’ -T kitten.jpg

结果展示

{
  "tabby": 0.27850738167762756,
  "lynx": 0.25299158692359924,
  "tiger_cat": 0.24496474862098694,
  "Egyptian_cat": 0.21722468733787537,
  "cougar": 0.002217544475570321
}

可能出现问题

官方文档出现问题集合
https://pytorch.org/serve/Troubleshooting.html

  • 出现503

解决方案,设置一下就好

curl -v -X PUT "http://localhost:8081/models/squeezenet1_1?min_worker=3&synchronous=true"
  • 出现404

需要检查 ‘curl -X http://127.0.0.1:8081/’ 下是不是有模型

  • 无模型
    新建模型
  • 有模型
    检查书写、格式、路径是不是出错
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/964919.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

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

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