千家信息网

如何在Podman容器中创建一个容器化的机器学习模型

发表于:2025-11-09 作者:千家信息网编辑
千家信息网最后更新 2025年11月09日,这篇文章主要为大家展示了"如何在Podman容器中创建一个容器化的机器学习模型",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"如何在Podman容器中创建一
千家信息网最后更新 2025年11月09日如何在Podman容器中创建一个容器化的机器学习模型

这篇文章主要为大家展示了"如何在Podman容器中创建一个容器化的机器学习模型",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"如何在Podman容器中创建一个容器化的机器学习模型"这篇文章吧。

准备

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

sudo dnf -y install podman

接下来,为容器创建一个新文件夹并切换到该目录。

mkdir deployment_container && cd deployment_container

TensorFlow 模型的 REST API

下一步是为机器学习模型创建 REST API。这个 github 仓库包含一个预训练模型,以及能让 REST API 工作的设置。

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

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。

swagger: "2.0"info:  description: This is the swagger file that goes with our server code  version: "1.0.0"  title: Tensorflow Podman Articleconsumes:  - "application/json"produces:  - "application/json"  basePath: "/" paths:  /survival_probability:    post:      operationId: "prediction.post"      tags:        - "Prediction"      summary: "The prediction data structure provided by the server application"      description: "Retrieve the chance of surviving the titanic disaster"      parameters:        - in: body          name: passenger          required: true          schema:            $ref: '#/definitions/PredictionPost'      responses:        '201':          description: 'Survival probability of an individual Titanic passenger' definitions:  PredictionPost:    type: object
server.py 和 requirements.txt

server.py 定义了启动 Connexion 服务器的入口点。

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

requirements.txt 定义了运行程序所需的 python 包。

connexiontensorflowpandas

容器化!

为了让 Podman 构建映像,请在上面的准备步骤中创建的 deployment_container 目录中创建一个名为 Dockerfile 的新文件:

FROM fedora:28 # File Author / MaintainerMAINTAINER Sven Boesiger  # Update the sourcesRUN dnf -y update --refresh # Install additional dependenciesRUN dnf -y install libstdc++ RUN dnf -y autoremove # Copy the application folder inside the containerADD /titanic_tf_ml_model /titanic_tf_ml_model # Get pip to download and install requirements:RUN pip3 install -r /titanic_tf_ml_model/requirements.txt # Expose portsEXPOSE 5000 # Set the default directory where CMD will executeWORKDIR /titanic_tf_ml_model # Set the default command to execute# when creating a new containerCMD python3 server.py

接下来,使用以下命令构建容器镜像:

podman build -t ml_deployment .

运行容器

随着容器镜像的构建和准备就绪,你可以使用以下命令在本地运行它:

podman run -p 5000:5000 ml_deployment

在 Web 浏览器中输入 http://0.0.0.0:5000/ui 访问 Swagger/Connexion UI 并测试模型:

当然,你现在也可以在应用中通过 REST API 访问模型。

以上是"如何在Podman容器中创建一个容器化的机器学习模型"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!

容器 模型 学习 中创 机器 命令 文件 内容 目录 篇文章 准备 运行 接下来 文件夹 服务器 镜像 帮助 应用 服务 输入 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 未来互联网大会领先科技 第四支付平台 网络安全 法院 软件开发需要学什么知识 网络安全包括web渗透吗 移动服务器坏了多久能修好 北京云鼎互动网络技术 缺考数据库系统工程师还能报吗 数据库的修改语句怎么写 网络技术学语言吗 计算机网络技术招生演讲稿 中电科网络安全证书 我的世界服务器qq群互聊 浪潮服务器进改ipmi 永宁县软件开发哪家专业 双创网络安全教育 网络安全设计方案范本 蚂蚁科技互联网金融 关于网络安全检查的报告 新疆网络安全教育基地 海淀区管理网络技术服务包括什么 数据库建立图书信息表实验总结 偃师软件开发报价 数据库表怎么插入记录 写脚本的人认识软件开发不 沈阳维可拓软件开发有限公司 网络安全漏洞与防范措施 微校宝北京网络技术联系方式 移动网络技术部考试 蚂蚁科技互联网金融 股票软件开发机构
0