日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)建一個(gè)容器化的機(jī)器學(xué)習(xí)模型

數(shù)據(jù)科學(xué)家在創(chuàng)建機(jī)器學(xué)習(xí)模型后,必須將其部署到生產(chǎn)中。要在不同的基礎(chǔ)架構(gòu)上運(yùn)行它,使用容器并通過(guò) REST API 公開模型是部署機(jī)器學(xué)習(xí)模型的常用方法。本文演示了如何在 Podman 容器中使用 Connexion 推出使用 REST API 的 TensorFlow 機(jī)器學(xué)習(xí)模型。

公司主營(yíng)業(yè)務(wù):成都網(wǎng)站制作、成都網(wǎng)站設(shè)計(jì)、外貿(mào)營(yíng)銷網(wǎng)站建設(shè)、移動(dòng)網(wǎng)站開發(fā)等業(yè)務(wù)。幫助企業(yè)客戶真正實(shí)現(xiàn)互聯(lián)網(wǎng)宣傳,提高企業(yè)的競(jìng)爭(zhēng)能力。成都創(chuàng)新互聯(lián)是一支青春激揚(yáng)、勤奮敬業(yè)、活力青春激揚(yáng)、勤奮敬業(yè)、活力澎湃、和諧高效的團(tuán)隊(duì)。公司秉承以“開放、自由、嚴(yán)謹(jǐn)、自律”為核心的企業(yè)文化,感謝他們對(duì)我們的高要求,感謝他們從不同領(lǐng)域給我們帶來(lái)的挑戰(zhàn),讓我們激情的團(tuán)隊(duì)有機(jī)會(huì)用頭腦與智慧不斷的給客戶帶來(lái)驚喜。成都創(chuàng)新互聯(lián)推出越秀免費(fèi)做網(wǎng)站回饋大家。

準(zhǔn)備

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

 
 
 
 
  1. sudo dnf -y install podman

接下來(lái),為容器創(chuàng)建一個(gè)新文件夾并切換到該目錄。

 
 
 
 
  1. mkdir deployment_container && cd deployment_container

TensorFlow 模型的 REST API

下一步是為機(jī)器學(xué)習(xí)模型創(chuàng)建 REST API。這個(gè) github 倉(cāng)庫(kù)包含一個(gè)預(yù)訓(xùn)練模型,以及能讓 REST API 工作的設(shè)置。

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

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

prediction.py 和 ml_model/

prediction.py 能進(jìn)行 Tensorflow 預(yù)測(cè),而 20x20x20 神經(jīng)網(wǎng)絡(luò)的權(quán)重位于文件夾 ml_model/ 中。

swagger.yaml

swagger.yaml 使用 Swagger規(guī)范 定義 Connexion 庫(kù)的 API。此文件包含讓你的服務(wù)器提供輸入?yún)?shù)驗(yàn)證、輸出響應(yīng)數(shù)據(jù)驗(yàn)證、URL 端點(diǎn)定義所需的所有信息。

額外地,Connexion 還將給你提供一個(gè)簡(jiǎn)單但有用的單頁(yè) Web 應(yīng)用,它演示了如何使用 Javascript 調(diào)用 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. basePath: "/"
  11. paths:
  12. /survival_probability:
  13. post:
  14. operationId: "prediction.post"
  15. tags:
  16. - "Prediction"
  17. summary: "The prediction data structure provided by the server application"
  18. description: "Retrieve the chance of surviving the titanic disaster"
  19. parameters:
  20. - in: body
  21. name: passenger
  22. required: true
  23. schema:
  24. $ref: '#/definitions/PredictionPost'
  25. responses:
  26. '201':
  27. description: 'Survival probability of an individual Titanic passenger'
  28. definitions:
  29. PredictionPost:
  30. type: object

server.py 和 requirements.txt

server.py 定義了啟動(dòng) Connexion 服務(wù)器的入口點(diǎn)。

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

requirements.txt 定義了運(yùn)行程序所需的 python 包。

 
 
 
 
  1. connexion
  2. tensorflow
  3. pandas

容器化!

為了讓 Podman 構(gòu)建映像,請(qǐng)?jiān)谏厦娴臏?zhǔn)備步驟中創(chuàng)建的 deployment_container 目錄中創(chuàng)建一個(gè)名為 Dockerfile 的新文件:

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

接下來(lái),使用以下命令構(gòu)建容器鏡像:

 
 
 
 
  1. podman build -t ml_deployment .

運(yùn)行容器

隨著容器鏡像的構(gòu)建和準(zhǔn)備就緒,你可以使用以下命令在本地運(yùn)行它:

 
 
 
 
  1. podman run -p 5000:5000 ml_deployment

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

當(dāng)然,你現(xiàn)在也可以在應(yīng)用中通過(guò) REST API 訪問(wèn)模型。


網(wǎng)頁(yè)標(biāo)題:創(chuàng)建一個(gè)容器化的機(jī)器學(xué)習(xí)模型
當(dāng)前鏈接:http://www.5511xx.com/article/cdjhpho.html