将 TensorFlow 企业版与 Deep Learning VM 搭配使用

本页面简要介绍了 Deep Learning VM Image ,并介绍了如何开始搭配使用 TensorFlow 企业版与 Deep Learning VM 实例。

在此示例中,您将创建一个 TensorFlow 企业版 Deep Learning VM 实例,使用 SSH 连接到该实例,打开 JupyterLab 笔记本,并运行有关如何搭配使用神经网络与 Keras 的分类教程。

Deep Learning VM 概览

Deep Learning VM Images 是一组针对数据科学和机器学习任务进行了优化的虚拟机器映像。所有映像都预安装了关键机器学习框架和工具。您可以在配备了 GPU 的实例上开箱即用,从而加快数据处理任务的速度。

Deep Learning VM 映像可用于支持框架和处理器的许多组合。目前有支持 TensorFlow Enterprise、TensorFlow、PyTorch 和通用高性能计算的映像,并且有仅适用于 CPU 和适用于支持 GPU 的工作流的版本。

要查看可用的框架列表,请参阅选择映像

准备工作

  1. 登录您的 Google Cloud 账号。如果您是 Google Cloud的新用户, 请创建账号,以便在 真实场景中评估我们产品的性能。新客户还可获享 $300 赠金,用于 运行、测试和部署工作负载。
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  5. Verify that billing is enabled for your Google Cloud project.

创建 Deep Learning VM 实例

如需创建 TensorFlow 企业版 Deep Learning VM 实例,请完成以下步骤:

  1. 在 Google Cloud 控制台中前往 Deep Learning VM Cloud Marketplace 页面。

    前往 Deep Learning VM Cloud Marketplace 页面

  2. 点击在 Compute Engine 上启动 。如果看到项目选择窗口,请选择要在其中创建实例的项目。如果这是您第一次启动 Compute Engine,则必须等待初始 API 配置过程完成。

  3. 新建 Deep Learning VM 部署 (New Deep Learning VM deployment) 页面上,输入部署名称 。该名称将作为虚拟机名称的基本组成部分。创建实例时,Compute Engine 会将 -vm 添加到此名称。

  4. GPU 数量 下,选择 。您无需使用 GPU 即可完成本指南中的说明。

  5. 框架下,选择TensorFlow 企业版 2.3 (CUDA 11.0)

  6. 在此示例中,您可以保留其余设置不变。

  7. 点击部署

您刚刚创建了第一个 Deep Learning VM 实例。 创建实例后,部署 管理器会打开。您可以在其中管理 Deep Learning VM 实例和其他部署。

使用 SSH 连接、打开笔记本并运行分类教程

请完成以下步骤,以设置与 Deep Learning VM 实例的 SSH 连接,打开 JupyterLab 笔记本,并运行有关如何搭配使用神经网络与 Keras 的教程:

  1. 如需完成这些步骤,您可以使用 Cloud Shell或安装了 Google Cloud CLI的任何 环境。您可以使用 gcloud CLI 与实例进行交互。

    • 如果您想使用 Cloud Shell,请在 Google Cloud 右上角点击 激活 Cloud Shell 按钮。

      Google Cloud Platform Console

    • 如果您想使用 gcloud CLI,请在本地机器上下载并 安装 Google Cloud CLI

  2. Cloud Shell 或本地终端窗口中,使用以下命令 创建与实例的 SSH 连接。 将 my-project-idmy-zone、 和 my-instance-name 替换为相关信息。

    gcloud compute ssh --project my-project-id --zone my-zone \
      my-instance-name -- -L 8080:localhost:8080
    
  3. 在本地浏览器中,访问 http://localhost:8080,以访问默认包含在实例中的 JupyterLab 笔记本。

  4. 在笔记本中,双击左侧的 tutorials 以打开该文件夹,然后找到并打开 tutorials/tf2_course/01_neural_nets_with_keras.ipynb

  5. 点击运行按钮 以 运行教程的单元。

后续步骤