diff --git a/notebooks/official/prediction/pytorch_image_classification_with_prebuilt_serving_containers.ipynb b/notebooks/official/prediction/pytorch_image_classification_with_prebuilt_serving_containers.ipynb index 617d69a8a..05cfbb060 100644 --- a/notebooks/official/prediction/pytorch_image_classification_with_prebuilt_serving_containers.ipynb +++ b/notebooks/official/prediction/pytorch_image_classification_with_prebuilt_serving_containers.ipynb @@ -33,25 +33,27 @@ "\n", "\n", "\n", - "\n", - " \n", - " \n", - " \n", + " \n", - "
\n", + " \n", " \n", - " \"Colab Run in Colab\n", + " \"Google
Open in Colab\n", "
\n", "
\n", - " \n", - " \"GitHub\n", - " View on GitHub\n", + " \n", + " \n", + " \"Google
Open in Colab Enterprise\n", "
\n", - "
\n", + " \n", " \n", - " \"Vertex\n", - " Open in Vertex AI Workbench\n", + " \"Vertex
Open in Workbench\n", "
\n", "
" + " \n", + " \n", + " \"GitHub
View on GitHub\n", + "
\n", + " \n", + "\n" ] }, { @@ -140,19 +142,26 @@ { "cell_type": "markdown", "metadata": { - "id": "i7EUnXsZhAGF" + "id": "7cc240e9c1a6" }, "source": [ - "## Installation\n", - "\n", - "Install the following packages required to execute this notebook." + "## Get started" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "9d6f71d52f3d" + }, + "source": [ + "### Install Vertex AI SDK for Python and other required packages\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "id": "2b4ef9b72d43" + "id": "39883d03df60" }, "outputs": [], "source": [ @@ -167,155 +176,92 @@ { "cell_type": "markdown", "metadata": { - "id": "58707a750154" + "id": "16220914acc5" }, "source": [ - "### Colab only: Uncomment the following cell to restart the kernel." + "### Restart runtime (Colab only)\n", + "\n", + "To use the newly installed packages, you must restart the runtime on Google Colab." ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "id": "f200f10a1da3" + "id": "157953ab28f0" }, "outputs": [], "source": [ - "# Automatically restart kernel after installs so that your environment can access the new packages\n", - "# import IPython\n", + "import sys\n", "\n", - "# app = IPython.Application.instance()\n", - "# app.kernel.do_shutdown(True)" + "if \"google.colab\" in sys.modules:\n", + "\n", + " import IPython\n", + "\n", + " app = IPython.Application.instance()\n", + " app.kernel.do_shutdown(True)" ] }, { "cell_type": "markdown", "metadata": { - "id": "BF1j6f9HApxa" + "id": "e669f8088ac3" }, "source": [ - "## Before you begin\n", - "\n", - "### Set up your Google Cloud project\n", - "\n", - "**The following steps are required, regardless of your notebook environment.**\n", - "\n", - "1. [Select or create a Google Cloud project](https://console.cloud.google.com/cloud-resource-manager). When you first create an account, you get a $300 free credit towards your compute/storage costs.\n", - "\n", - "2. [Make sure that billing is enabled for your project](https://cloud.google.com/billing/docs/how-to/modify-project).\n", - "\n", - "3. [Enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com).\n", - "\n", - "4. If you are running this notebook locally, you need to install the [Cloud SDK](https://cloud.google.com/sdk)." + "
\n", + "⚠️ The kernel is going to restart. Wait until it's finished before continuing to the next step. ⚠️\n", + "
\n" ] }, { "cell_type": "markdown", "metadata": { - "id": "WReHDGG5g0XY" + "id": "5dccb1c8feb6" }, "source": [ - "#### Set your project ID\n", + "### Authenticate your notebook environment (Colab only)\n", "\n", - "**If you don't know your project ID**, see the support page: [Locate the project ID](https://support.google.com/googleapi/answer/7014113)" + "Authenticate your environment on Google Colab.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "id": "oM1iC_MfAts1" + "id": "cc7251520a07" + }, + "outputs": [], + "source": [ + "import sys\n", + "\n", + "if \"google.colab\" in sys.modules:\n", + "\n", + " from google.colab import auth\n", + "\n", + " auth.authenticate_user()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "60763ee24ce0" + }, + "source": [ + "### Set Google Cloud project information and initialize Vertex AI SDK for Python\n", + "\n", + "To get started using Vertex AI, you must have an existing Google Cloud project and [enable the Vertex AI API](https://console.cloud.google.com/flows/enableapi?apiid=aiplatform.googleapis.com). Learn more about [setting up a project and a development environment](https://cloud.google.com/vertex-ai/docs/start/cloud-environment)." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "f02130bff721" }, "outputs": [], "source": [ "PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}\n", - "\n", - "# Set the project id\n", - "! gcloud config set project {PROJECT_ID}" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "region" - }, - "source": [ - "#### Region\n", - "\n", - "You can also change the `REGION` variable used by Vertex AI. Learn more about [Vertex AI regions](https://cloud.google.com/vertex-ai/docs/general/locations)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "tTy1gX11kCJY" - }, - "outputs": [], - "source": [ - "REGION = \"us-central1\" # @param {type: \"string\"}" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "sBCra4QMA2wR" - }, - "source": [ - "### Authenticate your Google Cloud account\n", - "\n", - "Depending on your Jupyter environment, you may have to manually authenticate. Follow the relevant instructions below." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "74ccc9e52986" - }, - "source": [ - "**1. Vertex AI Workbench**\n", - "* Do nothing as you are already authenticated." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "de775a3773ba" - }, - "source": [ - "**2. Local JupyterLab instance, uncomment and run:**" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "254614fa0c46" - }, - "outputs": [], - "source": [ - "# ! gcloud auth login" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "id": "ef21552ccea8" - }, - "source": [ - "**3. Colab, uncomment and run:**" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "603adbbf0532" - }, - "outputs": [], - "source": [ - "# from google.colab import auth\n", - "# auth.authenticate_user()" + "LOCATION = \"us-central1\" # @param {type:\"string\"}" ] }, { @@ -324,7 +270,7 @@ "id": "zgPO1eR3CYjk" }, "source": [ - "### Create a Cloud Storage bucket\n", + "#### Create a Cloud Storage bucket\n", "\n", "Create a storage bucket to store intermediate artifacts such as datasets." ] @@ -346,7 +292,7 @@ "id": "-EcIXiGsCePi" }, "source": [ - "**Only if your bucket doesn't already exist**: Run the following cell to create your Cloud Storage bucket." + "**If your bucket doesn't already exist**: Run the following cell to create your Cloud Storage bucket." ] }, { @@ -357,7 +303,31 @@ }, "outputs": [], "source": [ - "! gsutil mb -l {REGION} -p {PROJECT_ID} {BUCKET_URI}" + "! gsutil mb -l {LOCATION} -p {PROJECT_ID} {BUCKET_URI}" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "init_aip:mbsdk,all" + }, + "source": [ + "#### Initialize Vertex AI SDK for Python\n", + "\n", + "Initialize the Vertex AI SDK for Python for your project." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "BnBAXs5XkCJZ" + }, + "outputs": [], + "source": [ + "from google.cloud import aiplatform\n", + "\n", + "aiplatform.init(project=PROJECT_ID, location=LOCATION, staging_bucket=BUCKET_URI)" ] }, { @@ -385,33 +355,10 @@ "\n", "import tensorflow as tf\n", "import torch\n", - "from google.cloud import aiplatform\n", "from PIL import Image\n", "from torchvision import models" ] }, - { - "cell_type": "markdown", - "metadata": { - "id": "init_aip:mbsdk,all" - }, - "source": [ - "### Initialize Vertex AI SDK for Python\n", - "\n", - "Initialize the Vertex AI SDK for Python for your project." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "BnBAXs5XkCJZ" - }, - "outputs": [], - "source": [ - "aiplatform.init(project=PROJECT_ID, location=REGION, staging_bucket=BUCKET_URI)" - ] - }, { "cell_type": "markdown", "metadata": {