OpenShift 4 - 在 OpenShift 上运行物体检测 AI 应用

OpenShift / RHEL / DevSecOps 汇总目录

说明:本文已经在 OpenShift 4.14 + RHODS 2.5.0 的环境中验证

说明:请先根据《OpenShift 4 - 部署 OpenShift AI 环境,运行 AI/ML 应用(视频)》一文完成 OpenShift AI 环境的安装。

注意:如无特殊说明,和 OpenShift AI 相关的 Blog 均无需 GPU。

文章目录

部署后端模型

在 Jupyter Notebook 中我们先用本地图片测试一个预先训练好的机器学习模型,然后将该模型的功能封装为一个 REST 服务。在完成本地测后再将物体识别模块部署到 OpenShift 上。

运行后端模型

  1. 在 OpenShift AI 中启动 notebook server 环境,notebook 镜像使用 TensorFlow 2023.2 即可。
  2. 在 Jupyter Notebook 界面中导入 https://github.com/rh-aiservices-bu/object-detection-rest.git 仓库。
  3. 在 Launcher 中进入 Terminal,然后执行以下命令安装 Pillow。
bash 复制代码
(app-root) (app-root) pip install Pillow==9.5.0
Collecting Pillow==9.5.0
  Downloading Pillow-9.5.0-cp39-cp39-manylinux_2_28_x86_64.whl (3.4 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 3.4/3.4 MB 84.0 MB/s eta 0:00:00
Installing collected packages: Pillow
  Attempting uninstall: Pillow
    Found existing installation: Pillow 10.1.0
    Uninstalling Pillow-10.1.0:
      Successfully uninstalled Pillow-10.1.0
Successfully installed Pillow-9.5.0

[notice] A new release of pip available: 22.2.2 -> 23.3.2
[notice] To update, run: pip install --upgrade pip
  1. 打开 1_explore.ipynb 文件,然后点击 Run > Run All Cells 菜单。
  2. 运行完成后会识别并标记出 twodogs.jpg 图片的 dog。

将后端模型部署为 REST 服务

  1. 根据 Notebook 的说明依次运行 2_predict.ipynb、3_run_flask.ipynb、4_test_flask.ipynb。其中 3_run_flask.ipynb 会在 http://127.0.0.1:5000 提供运行物体识别的 REST 服务。
  2. 在 OpenShift 中创建 object-detect 项目。
  3. 在 OpenShift 的开发者视图中进入 "+添加" > "从 Github 导入",在 Git Repo URL 中填入 https://github.com/rh-aiservices-bu/object-detection-rest.git。在按下图完成配置后点击 "创建"。
  4. 部署完成后可以打开下图 object-detect-rest 路由的地址,将显示 {"status":"ok"},说明 REST 服务正常运行。
  5. 打开 4_test_flask.ipynb 文件,将 my_route 变量的内容改为上图的路由地址,然后再运行该文件并确认可以正常识别图片中的物体。

部署前端应用

  1. 再次使用 "从 Git 导入" 功能部署 https://github.com/rh-aiservices-bu/object-detection-app.git。
    其中需要在部署中增加一个环境变量 OBJECT_DETECTION_URL=http://object-detection-rest:8080/predictions
  2. 完成部署后打开下图 object-detect-ui 路由的地址。
  3. 用带有摄像头的电脑打开 object-detect-ui 路由的地址,然后可拍摄图片确认物体识别结果。

参考

https://redhat-scholars.github.io/rhods-od-workshop/rhods-od-workshop/index.html

相关推荐
张人玉1 小时前
人工智能——猴子摘香蕉问题
人工智能
草莓屁屁我不吃1 小时前
Siri因ChatGPT-4o升级:我们的个人信息还安全吗?
人工智能·安全·chatgpt·chatgpt-4o
小言从不摸鱼1 小时前
【AI大模型】ChatGPT模型原理介绍(下)
人工智能·python·深度学习·机器学习·自然语言处理·chatgpt
AI科研视界2 小时前
ChatGPT+2:修订初始AI安全性和超级智能假设
人工智能·chatgpt
霍格沃兹测试开发学社测试人社区2 小时前
人工智能 | 基于ChatGPT开发人工智能服务平台
软件测试·人工智能·测试开发·chatgpt
小R资源2 小时前
3款免费的GPT类工具
人工智能·gpt·chatgpt·ai作画·ai模型·国内免费
artificiali5 小时前
Anaconda配置pytorch的基本操作
人工智能·pytorch·python
营赢盈英5 小时前
Allow anonymous access to my Azure OpenAI chat bot
ai·openai·azure·webapps
程序员小川5 小时前
Ubuntu22.04安装paddle
ai·cuda·paddle·cudnn
酱香编程,风雨兼程5 小时前
深度学习——基础知识
人工智能·深度学习