成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

創建一個容器化的機器學習模型

人工智能 機器學習 架構
數據科學家在創建機器學習模型后,必須將其部署到生產中。要在不同的基礎架構上運行它,使用容器并通過 REST API 公開模型是部署機器學習模型的常用方法。本文演示了如何在 Podman 容器中使用 Connexion 推出使用 REST API 的 TensorFlow 機器學習模型。

[[252634]]

數據科學家在創建機器學習模型后,必須將其部署到生產中。要在不同的基礎架構上運行它,使用容器并通過 REST API 公開模型是部署機器學習模型的常用方法。本文演示了如何在 Podman 容器中使用 Connexion 推出使用 REST API 的 TensorFlow 機器學習模型。

準備

首先,使用以下命令安裝 Podman:

  1. sudo dnf -y install podman

接下來,為容器創建一個新文件夾并切換到該目錄。

  1. mkdir deployment_container && cd deployment_container

TensorFlow 模型的 REST API

下一步是為機器學習模型創建 REST API。這個 github 倉庫包含一個預訓練模型,以及能讓 REST API 工作的設置。

使用以下命令在 deployment_container 目錄中克隆它:

  1. git clone https://github.com/svenboesiger/titanic_tf_ml_model.git

prediction.py 和 ml_model/

prediction.py 能進行 Tensorflow 預測,而 20x20x20 神經網絡的權重位于文件夾 ml_model/ 中。

swagger.yaml

swagger.yaml 使用 Swagger規范 定義 Connexion 庫的 API。此文件包含讓你的服務器提供輸入參數驗證、輸出響應數據驗證、URL 端點定義所需的所有信息。

額外地,Connexion 還將給你提供一個簡單但有用的單頁 Web 應用,它演示了如何使用 Javascript 調用 API 和更新 DOM。

  1. swagger: "2.0"
  2. info:
  3. description: This is the swagger file that goes with our server code
  4. version: "1.0.0"
  5. title: Tensorflow Podman Article
  6. consumes:
  7. - "application/json"
  8. produces:
  9. - "application/json"
  10.  
  11.  
  12. basePath: "/"
  13.  
  14. paths:
  15. /survival_probability:
  16. post:
  17. operationId: "prediction.post"
  18. tags:
  19. - "Prediction"
  20. summary: "The prediction data structure provided by the server application"
  21. description: "Retrieve the chance of surviving the titanic disaster"
  22. parameters:
  23. - in: body
  24. name: passenger
  25. required: true
  26. schema:
  27. $ref: '#/definitions/PredictionPost'
  28. responses:
  29. '201':
  30. description: 'Survival probability of an individual Titanic passenger'
  31.  
  32. definitions:
  33. PredictionPost:
  34. type: object

server.py 和 requirements.txt

server.py 定義了啟動 Connexion 服務器的入口點。

  1. import connexion
  2.  
  3. app = connexion.App(__name__, specification_dir='./')
  4.  
  5. app.add_api('swagger.yaml')
  6.  
  7. if __name__ == '__main__':
  8. app.run(debug=True)

requirements.txt 定義了運行程序所需的 python 包。

  1. connexion
  2. tensorflow
  3. pandas

容器化!

為了讓 Podman 構建映像,請在上面的準備步驟中創建的 deployment_container 目錄中創建一個名為 Dockerfile 的新文件:

  1. FROM fedora:28
  2.  
  3. # File Author / Maintainer
  4. MAINTAINER Sven Boesiger <donotspam@ujelang.com>
  5.  
  6. # Update the sources
  7. RUN dnf -y update --refresh
  8.  
  9. # Install additional dependencies
  10. RUN dnf -y install libstdc++
  11.  
  12. RUN dnf -y autoremove
  13.  
  14. # Copy the application folder inside the container
  15. ADD /titanic_tf_ml_model /titanic_tf_ml_model
  16.  
  17. # Get pip to download and install requirements:
  18. RUN pip3 install -r /titanic_tf_ml_model/requirements.txt
  19.  
  20. # Expose ports
  21. EXPOSE 5000
  22.  
  23. # Set the default directory where CMD will execute
  24. WORKDIR /titanic_tf_ml_model
  25.  
  26. # Set the default command to execute
  27. # when creating a new container
  28. CMD python3 server.py

接下來,使用以下命令構建容器鏡像:

  1. podman build -t ml_deployment .

運行容器

隨著容器鏡像的構建和準備就緒,你可以使用以下命令在本地運行它:

  1. podman run -p 5000:5000 ml_deployment

在 Web 瀏覽器中輸入 http://0.0.0.0:5000/ui 訪問 Swagger/Connexion UI 并測試模型:

當然,你現在也可以在應用中通過 REST API 訪問模型。 

責任編輯:龐桂玉 來源: Linux中國
相關推薦

2024-06-13 08:36:11

2024-08-15 14:48:57

2020-10-14 14:18:33

機器學習機器學習架構人工智能

2017-10-13 15:59:24

iPhone機器學習iOS

2022-06-02 15:42:05

Python機器學習

2024-04-10 12:39:08

機器學習python

2020-11-20 10:50:01

Docker容器

2021-11-02 08:00:00

機器學習API技術

2025-01-21 08:11:24

2018-12-29 08:00:00

機器學習TensorFlowKubeflow

2023-12-25 10:53:54

機器學習模型性能

2010-08-05 15:46:13

Flex行為Flex效果

2020-09-28 12:42:17

機器學習語言GitHub

2021-04-09 10:02:29

機器學習人工智能計算機

2017-07-25 09:19:02

2022-03-25 11:11:50

機器學習TiDBSQL

2021-06-23 16:40:58

JavaTomcatWeb

2024-09-30 05:43:44

2021-08-30 09:25:25

Bert模型PyTorch語言

2020-02-21 11:23:11

機器學習技術人生第一份工作
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 国产精品久久国产精品 | 久久国产传媒 | 国产精品黄色 | 精品久久久网站 | 一区二区国产在线观看 | 精品欧美一区二区三区精品久久 | 极品销魂美女一区二区 | 亚洲天堂999 | 91视频网 | 精品成人 | 在线小视频 | 91国内视频在线 | 免费毛片www com cn | 日本精品一区二区 | 国产资源网 | 亚洲欧美日韩成人在线 | 国产精品二区三区 | 欧美日韩综合视频 | 操操日| 国产在线网站 | 午夜资源 | 最近中文字幕在线视频1 | 欧美日韩国产不卡 | 欧美三级在线 | 亚洲精品久久久一区二区三区 | 亚洲三级国产 | 欧美一区二区 | 婷婷久久网 | 日韩免费福利视频 | av片免费 | 国产激情在线 | 亚洲a视频 | 亚洲欧美网| 中文精品视频 | 成人精品一区 | 日本亚洲欧美 | 激情影院久久 | 亚洲精品电影网在线观看 | 在线播放一区二区三区 | 久久男人天堂 | 国产日韩精品一区二区 |