打包与容器化

端到端机器学习

Joshua Stapleton

Machine Learning Engineer

部署与容器化

部署

  • 将模型与依赖打包为单元
  • 可在不同环境运行
  • 容器化与部署的事实标准是 Docker

机器学习生命周期的部署阶段

端到端机器学习

Docker

  • 通过容器简化开发的平台

容器:

  • 将应用打包为独立制品
  • 设计为跨平台
  • 获取 Docker

 

DataCamp Docker 课程

Docker 标志

端到端机器学习

Docker 用法(上)

Dockerfile:构建容器的指令

# Use an official Python runtime as a parent image
FROM Python:3.7

# Set the working directory in the container to /app WORKDIR /ML_pipeline
# Copy the current directory contents into the container at /app ADD . /ML_pipeline
# Install any needed packages specified in requirements.txt RUN pip install --no-cache-dir -r requirements.txt
端到端机器学习

Docker 用法(下)

# ... continued
# Make port 80 available to the world outside this container
EXPOSE 80
# Define environment variable
ENV NAME World
# Run app.py when the container launches
CMD ["Python", "ML_pipeline.py"]

构建镜像:

docker build -t heart_disease_model .
端到端机器学习

容器标记(Tagging)

标记:

docker tag heart_disease_model:latest heart_disease_model:1.0
  • 便于识别和管理镜像/容器。
  • 有助于维护完善的模型注册表。
  • 标记后即可部署!

将部署可视化为箭头

端到端机器学习

最佳实践

Docker 让模型打包更简单,但需注意:

  • 注重安全
  • 不要包含敏感数据
  • 使用可信镜像(经验证的开发者)

如应用包含敏感信息:

  • 使用环境变量
  • 例如:连接串/密码

安全锁

端到端机器学习

¡Vamos a practicar!

端到端机器学习

Preparing Video For Download...