mirror of
https://github.com/GoogleCloudPlatform/vertex-ai-samples.git
synced 2026-09-26 14:42:04 +00:00
chore,refactor(egen): Added opencv-python-headless and tensorflow==2.15.1 packages and cleanup code for local files and cloud storage bucket (#3258)
* chore,refactor(egen): Added opencv-python-headless and tensorflow==2.15.1 packages in installation step, Added import os statement in set machine type configuaration cell, Added cloud storage bucket and local files cleanup code, refactored code according to template guidelines and performed lintr test * refactor(Egen):Done changes according to @kittyabs review and performed linter test. * chore(egen): added IS_TESTING part while creating artifact repository and perfomred linter test --------- Co-authored-by: sriramya2610 <sriramya.peddapally@egen.ai>
This commit is contained in:
co-authored by
sriramya2610
parent
0791c52923
commit
0dcce973bf
+134
-159
@@ -32,24 +32,26 @@
|
||||
"# Vertex AI migration: Custom image classification with a custom training container\n",
|
||||
"\n",
|
||||
"<table align=\"left\">\n",
|
||||
"\n",
|
||||
" <td>\n",
|
||||
"<a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/sdk-custom-image-classification-custom-container.ipynb\" target='_blank'>\n",
|
||||
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Colab logo\"> Run in Colab\n",
|
||||
" <td style=\"text-align: center\">\n",
|
||||
" <a href=\"https://colab.research.google.com/github/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/sdk-custom-image-classification-custom-container.ipynb\">\n",
|
||||
" <img src=\"https://cloud.google.com/ml-engine/images/colab-logo-32px.png\" alt=\"Google Colaboratory logo\"><br> Open in Colab\n",
|
||||
" </a>\n",
|
||||
" </td>\n",
|
||||
" <td>\n",
|
||||
"<a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/sdk-custom-image-classification-custom-container.ipynb\" target='_blank'>\n",
|
||||
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\">\n",
|
||||
" View on GitHub\n",
|
||||
" <td style=\"text-align: center\">\n",
|
||||
" <a href=\"https://console.cloud.google.com/vertex-ai/colab/import/https:%2F%2Fraw.githubusercontent.com%2FGoogleCloudPlatform%2Fvertex-ai-samples%2Fmain%2Fnotebooks%2Fofficial%2Fmigration%2Fsdk-custom-image-classification-custom-container.ipynb\">\n",
|
||||
" <img width=\"32px\" src=\"https://cloud.google.com/ml-engine/images/colab-enterprise-logo-32px.png\" alt=\"Google Cloud Colab Enterprise logo\"><br> Open in Colab Enterprise\n",
|
||||
" </a>\n",
|
||||
" </td> \n",
|
||||
" <td style=\"text-align: center\">\n",
|
||||
" <a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/official/migration/sdk-custom-image-classification-custom-container.ipynb\">\n",
|
||||
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\"><br> Open in Workbench\n",
|
||||
" </a>\n",
|
||||
" </td>\n",
|
||||
" <td>\n",
|
||||
"<a href=\"https://console.cloud.google.com/vertex-ai/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/vertex-ai-samples/main/notebooks/official/migration/sdk-custom-image-classification-custom-container.ipynb\" target='_blank'>\n",
|
||||
" <img src=\"https://lh3.googleusercontent.com/UiNooY4LUgW_oTvpsNhPpQzsstV5W8F7rYgxgGBD85cWJoLmrOzhVs_ksK_vgx40SHs7jCqkTkCk=e14-rj-sc0xffffff-h130-w32\" alt=\"Vertex AI logo\">\n",
|
||||
" Open in Vertex AI Workbench\n",
|
||||
" <td style=\"text-align: center\">\n",
|
||||
" <a href=\"https://github.com/GoogleCloudPlatform/vertex-ai-samples/blob/main/notebooks/official/migration/sdk-custom-image-classification-custom-container.ipynb\">\n",
|
||||
" <img src=\"https://cloud.google.com/ml-engine/images/github-logo-32px.png\" alt=\"GitHub logo\"><br> View on GitHub\n",
|
||||
" </a>\n",
|
||||
" </td> \n",
|
||||
" </td>\n",
|
||||
"</table>"
|
||||
]
|
||||
},
|
||||
@@ -78,23 +80,23 @@
|
||||
"\n",
|
||||
"This tutorial uses the following Google Cloud ML services and resources:\n",
|
||||
"\n",
|
||||
"- *Vertex AI Training*\n",
|
||||
"- *Vertex AI Model Registry*\n",
|
||||
"- *Vertex AI Batch Predictions*\n",
|
||||
"- *Vertex AI Endpoints*\n",
|
||||
"- Vertex AI Training\n",
|
||||
"- Vertex AI Model Registry\n",
|
||||
"- Vertex AI batch Predictions\n",
|
||||
"- Vertex AI endpoints\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"The steps performed include:\n",
|
||||
"\n",
|
||||
"- *Package the training code into a python application.*\n",
|
||||
"- *Containerize the training application using Cloud Build and Artifact Registry.*\n",
|
||||
"- *Create a custom container training job in Vertex AI and run it.*\n",
|
||||
"- *Evaluate the model generated from the training job.*\n",
|
||||
"- *Create a model resource for the trained model in Vertex AI Model Registry.*\n",
|
||||
"- *Run a Vertex AI batch prediction job.*\n",
|
||||
"- *Deploy the model resource to a Vertex AI Endpoint.*\n",
|
||||
"- *Run a online prediction job on the model resource.*\n",
|
||||
"- *Clean up the resources created.*"
|
||||
"- Package the training code into a python application.\n",
|
||||
"- Containerize the training application using Cloud Build and Artifact Registry.\n",
|
||||
"- Create a custom container training job in Vertex AI and run it.\n",
|
||||
"- Evaluate the model generated from the training job.\n",
|
||||
"- Create a model resource for the trained model in Vertex AI Model Registry.\n",
|
||||
"- Run a Vertex AI batch prediction job.\n",
|
||||
"- Deploy the model resource to a Vertex AI endpoint.\n",
|
||||
"- Run a online prediction job on the model resource.\n",
|
||||
"- Clean up the resources created."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -130,15 +132,22 @@
|
||||
"to generate a cost estimate based on your projected usage."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "f0316df526f8"
|
||||
},
|
||||
"source": [
|
||||
"## Get started"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "iMHz63rPbq6P"
|
||||
},
|
||||
"source": [
|
||||
"## Installation\n",
|
||||
"\n",
|
||||
"Install the packages required for executing this notebook."
|
||||
"### Install Vertex AI SDK for Python and other required packages"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -150,106 +159,124 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"! pip3 install --upgrade google-cloud-aiplatform \\\n",
|
||||
" google-cloud-storage -q\n",
|
||||
" google-cloud-storage \\\n",
|
||||
" opencv-python-headless \\\n",
|
||||
" tensorflow==2.15.1 -q\n",
|
||||
"\n",
|
||||
"import os\n",
|
||||
"if os.getenv(\"IS_TESTING\"):\n",
|
||||
" ! apt-get update && apt-get install -y python3-opencv-headless\n",
|
||||
" ! apt-get install -y libgl1-mesa-dev\n",
|
||||
" ! pip3 install --upgrade opencv-python-headless -q\n",
|
||||
" ! pip3 install tensorflow==2.9 -q"
|
||||
" ! pip3 install tensorflow==2.15.1 -q"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "58707a750154"
|
||||
"id": "ff555b32bab8"
|
||||
},
|
||||
"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": "f09b4dff629a"
|
||||
},
|
||||
"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": "WReHDGG5g0XY"
|
||||
"id": "4a2b7b59bbf7"
|
||||
},
|
||||
"source": [
|
||||
"#### Set your project ID\n",
|
||||
"<div class=\"alert alert-block alert-warning\">\n",
|
||||
"<b>⚠️ The kernel is going to restart. Wait until it's finished before continuing to the next step. ⚠️</b>\n",
|
||||
"</div>"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "f82e28c631cc"
|
||||
},
|
||||
"source": [
|
||||
"### Authenticate your notebook environment (Colab only)\n",
|
||||
"\n",
|
||||
"**If you don't know your project ID**, try the following:\n",
|
||||
"* Run `gcloud config list`.\n",
|
||||
"* Run `gcloud projects list`.\n",
|
||||
"* See the support page: [Locate the project ID](https://support.google.com/googleapi/answer/7014113)"
|
||||
"Authenticate your environment on Google Colab."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "oM1iC_MfAts1"
|
||||
"id": "46604f70e831"
|
||||
},
|
||||
"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": "91842ef41bbd"
|
||||
},
|
||||
"source": [
|
||||
"### Set Google Cloud project information\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": "294fe4e5a671"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"PROJECT_ID = \"[your-project-id]\" # @param {type:\"string\"}\n",
|
||||
"\n",
|
||||
"# Set the project id\n",
|
||||
"! gcloud config set project {PROJECT_ID}"
|
||||
"LOCATION = \"us-central1\" # @param {type:\"string\"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "region"
|
||||
"id": "0bd7a5e762cc"
|
||||
},
|
||||
"source": [
|
||||
"#### Set the region\n",
|
||||
"\n",
|
||||
"**Optional**: Update the 'REGION' variable to specify the region that you want to use. Learn more about [Vertex AI regions](https://cloud.google.com/vertex-ai/docs/general/locations)."
|
||||
"### UUID\n",
|
||||
"If you're in a live tutorial session, you might be using a shared test account or project. To avoid name collisions between users on resources created, create a uuid for each instance session, and append it onto the name of resources you create in this tutorial."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "nsN5NJKSu-GU"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"REGION = \"us-central1\" # @param {type: \"string\"}"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "timestamp"
|
||||
},
|
||||
"source": [
|
||||
"#### UUID\n",
|
||||
"\n",
|
||||
"If you are in a live tutorial session, you might be using a shared test account or project. To avoid name collisions between users on resources created, you create a uuid for each instance session, and append it onto the name of resources you create in this tutorial.\n"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "timestamp"
|
||||
"id": "3ee72715c0fd"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
@@ -265,67 +292,6 @@
|
||||
"UUID = generate_uuid()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "sBCra4QMA2wR"
|
||||
},
|
||||
"source": [
|
||||
"### Authenticate your Google Cloud account\n",
|
||||
"\n",
|
||||
"To authenticate your Google Cloud account, follow the instructions for your Jupyter environment:\n",
|
||||
"\n",
|
||||
"**1. Vertex AI Workbench**\n",
|
||||
"<br>You are already authenticated.\n",
|
||||
"\n",
|
||||
"**2. Local JupyterLab instance**\n",
|
||||
"<br>Uncomment and run the following code:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "254614fa0c46"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# ! gcloud auth login"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "ef21552ccea8"
|
||||
},
|
||||
"source": [
|
||||
"**3. Colab**\n",
|
||||
"<br>Uncomment and run the following code:"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"metadata": {
|
||||
"id": "603adbbf0532"
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# from google.colab import auth\n",
|
||||
"\n",
|
||||
"# auth.authenticate_user()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
"id": "c13224697bfb"
|
||||
},
|
||||
"source": [
|
||||
"**4. Service account or other**\n",
|
||||
"* See how to grant Cloud Storage permissions to your service account at https://cloud.google.com/storage/docs/gsutil/commands/iam#ch-examples."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {
|
||||
@@ -365,7 +331,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"! gsutil mb -l $REGION -p $PROJECT_ID $BUCKET_URI"
|
||||
"! gsutil mb -l $LOCATION -p $PROJECT_ID $BUCKET_URI"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -416,7 +382,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"aiplatform.init(project=PROJECT_ID, location=REGION, staging_bucket=BUCKET_URI)"
|
||||
"aiplatform.init(project=PROJECT_ID, location=LOCATION, staging_bucket=BUCKET_URI)"
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -434,9 +400,9 @@
|
||||
"\n",
|
||||
"You can set hardware accelerators for training and prediction.\n",
|
||||
"\n",
|
||||
"Set the variables `TRAIN_GPU/TRAIN_NGPU` and `DEPLOY_GPU/DEPLOY_NGPU` to use a container image supporting a GPU and the number of GPUs allocated to the virtual machine (VM) instance. For example, to use a GPU container image with 4 Nvidia Telsa K80 GPUs allocated to each VM, you would specify:\n",
|
||||
"Set the variables `TRAIN_GPU/TRAIN_NGPU` and `DEPLOY_GPU/DEPLOY_NGPU` to use a container image supporting a GPU and the number of GPUs allocated to the virtual machine (VM) instance. For example, to use a GPU container image with 4 Nvidia Telsa T4 GPUs allocated to each VM, you would specify:\n",
|
||||
"\n",
|
||||
" (aiplatform.gapic.AcceleratorType.NVIDIA_TESLA_K80, 4)\n",
|
||||
" (aiplatform.gapic.AcceleratorType.NVIDIA_TESLA_T4, 4)\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"Otherwise specify `(None, None)` to use a container image to run on a CPU.\n",
|
||||
@@ -519,7 +485,7 @@
|
||||
" - `standard`: 2 vCPUs\n",
|
||||
" - `highcpu`: 2, 4 and 8 vCPUs\n",
|
||||
"\n",
|
||||
"*Note: You may also use n2 and e2 machine types for training and deployment, but they do not support GPUs*."
|
||||
"*Note: You may also use n2 and e2 machine types for training and deployment, but they don't support GPUs*."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -530,6 +496,8 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import os\n",
|
||||
"\n",
|
||||
"MACHINE_TYPE = \"n1-standard\"\n",
|
||||
"\n",
|
||||
"VCPU = \"4\"\n",
|
||||
@@ -753,7 +721,7 @@
|
||||
"For this step, your Dockerfile does:\n",
|
||||
"1. Install a pre-defined container image from TensorFlow repository for deep learning images.\n",
|
||||
"2. Copies in the Python training code, to be shown subsequently.\n",
|
||||
"3. Sets the entry into the Python training script as `trainer/task.py`. Note that the `.py` is dropped in the ENTRYPOINT command, as it is implied."
|
||||
"3. Sets the entry into the Python training script as `trainer/task.py`. Note that the `.py` is dropped in the ENTRYPOINT command, as it's implied."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -831,7 +799,7 @@
|
||||
"source": [
|
||||
"REPOSITORY = \"my-docker-repo\"\n",
|
||||
"\n",
|
||||
"! gcloud artifacts repositories create {REPOSITORY} --repository-format=docker --location={REGION} --description=\"Docker repository\"\n",
|
||||
"! gcloud artifacts repositories create {REPOSITORY} --repository-format=docker --location={LOCATION} --description=\"Docker repository\"\n",
|
||||
"\n",
|
||||
"! gcloud artifacts repositories list"
|
||||
]
|
||||
@@ -863,7 +831,7 @@
|
||||
"\n",
|
||||
"TAG = \"latest\"\n",
|
||||
"TRAIN_IMAGE = (\n",
|
||||
" f\"{REGION}-docker.pkg.dev/{PROJECT_ID}/{REPOSITORY}/{CONTAINER_NAME}:{TAG}\"\n",
|
||||
" f\"{LOCATION}-docker.pkg.dev/{PROJECT_ID}/{REPOSITORY}/{CONTAINER_NAME}:{TAG}\"\n",
|
||||
")"
|
||||
]
|
||||
},
|
||||
@@ -898,7 +866,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"%cd custom\n",
|
||||
"!gcloud builds submit --region={REGION} --tag=$TRAIN_IMAGE\n",
|
||||
"!gcloud builds submit --region={LOCATION} --tag=$TRAIN_IMAGE\n",
|
||||
"%cd .."
|
||||
]
|
||||
},
|
||||
@@ -957,7 +925,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"job = aiplatform.CustomContainerTrainingJob(\n",
|
||||
" display_name=\"cifar10_\" + UUID, container_uri=TRAIN_IMAGE\n",
|
||||
" display_name=\"cifar10_\" + \"unique\", container_uri=TRAIN_IMAGE\n",
|
||||
")\n",
|
||||
"\n",
|
||||
"print(job)"
|
||||
@@ -1079,7 +1047,7 @@
|
||||
"\n",
|
||||
"For model evaluation, you load the CIFAR10 test (holdout) data from `tf.keras.datasets`, using the method `load_data()`. This returns the dataset as a tuple of two elements. The first element is the training data and the second is the test data. Each element is also a tuple of two elements: the image data, and the corresponding labels.\n",
|
||||
"\n",
|
||||
"You don't need the training data, and hence why it is loaded as `(_, _)`.\n",
|
||||
"You don't need the training data, and hence why it's loaded as `(_, _)`.\n",
|
||||
"\n",
|
||||
"Before you run the data through evaluation, you need to preprocess it:\n",
|
||||
"\n",
|
||||
@@ -1132,7 +1100,7 @@
|
||||
"source": [
|
||||
"## Serving function for image data\n",
|
||||
"\n",
|
||||
"To pass images to the prediction service, you encode the compressed (e.g., JPEG) image bytes into base 64., which makes the content safe from modification while transmitting binary data over the network. Since this deployed model expects input data as raw (uncompressed) bytes, you need to ensure that the base 64 encoded data gets converted back to raw bytes before it is passed as input to the deployed model.\n",
|
||||
"To pass images to the prediction service, you encode the compressed (e.g., JPEG) image bytes into base 64., which makes the content safe from modification while transmitting binary data over the network. Since this deployed model expects input data as raw (uncompressed) bytes, you need to ensure that the base 64 encoded data gets converted back to raw bytes before it's passed as input to the deployed model.\n",
|
||||
"\n",
|
||||
"To resolve this, define a serving function (`serving_fn`) and attach it to the model as a preprocessing step. Add a `@tf.function` decorator so the serving function is fused to the underlying model (instead of upstream on a CPU).\n",
|
||||
"\n",
|
||||
@@ -1250,7 +1218,7 @@
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"model = aiplatform.Model.upload(\n",
|
||||
" display_name=\"cifar10_\" + UUID,\n",
|
||||
" display_name=\"cifar10_\" + \"unique\",\n",
|
||||
" artifact_uri=MODEL_DIR,\n",
|
||||
" serving_container_image_uri=DEPLOY_IMAGE,\n",
|
||||
" sync=False,\n",
|
||||
@@ -1269,7 +1237,7 @@
|
||||
"\n",
|
||||
"### Get test items\n",
|
||||
"\n",
|
||||
"You will use examples out of the test (holdout) portion of the dataset as a test items."
|
||||
"You use examples out of the test (holdout) portion of the dataset as a test items."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1294,7 +1262,7 @@
|
||||
},
|
||||
"source": [
|
||||
"### Prepare the request content\n",
|
||||
"You are going to send the CIFAR10 images as compressed JPG image, instead of the raw uncompressed bytes:\n",
|
||||
"You're going to send the CIFAR10 images as compressed JPG image, instead of the raw uncompressed bytes:\n",
|
||||
"\n",
|
||||
"- `cv2.imwrite`: Use openCV to write the uncompressed image to disk as a compressed JPEG image.\n",
|
||||
" - Denormalize the image data from \\[0,1) range back to [0,255).\n",
|
||||
@@ -1418,7 +1386,7 @@
|
||||
"MAX_NODES = 1\n",
|
||||
"\n",
|
||||
"batch_predict_job = model.batch_predict(\n",
|
||||
" job_display_name=\"cifar10_\" + UUID,\n",
|
||||
" job_display_name=\"cifar10_\" + \"unique\",\n",
|
||||
" gcs_source=gcs_input_uri,\n",
|
||||
" gcs_destination_prefix=BUCKET_URI,\n",
|
||||
" instances_format=\"jsonl\",\n",
|
||||
@@ -1535,7 +1503,7 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"DEPLOYED_NAME = \"cifar10-\" + UUID\n",
|
||||
"DEPLOYED_NAME = \"cifar10-\" + \"unique\"\n",
|
||||
"\n",
|
||||
"TRAFFIC_SPLIT = {\"0\": 100}\n",
|
||||
"\n",
|
||||
@@ -1671,7 +1639,7 @@
|
||||
"source": [
|
||||
"## Undeploy the model\n",
|
||||
"\n",
|
||||
"When you are done doing predictions, you undeploy the model from the `Endpoint` resouce. This deprovisions all compute resources and ends billing for the deployed model."
|
||||
"When you're done doing predictions, you undeploy the model from the `Endpoint` resouce. This deprovisions all compute resources and ends billing for the deployed model."
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -1709,8 +1677,6 @@
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"delete_bucket = False\n",
|
||||
"\n",
|
||||
"# Delete the model using the Vertex model object\n",
|
||||
"model.delete()\n",
|
||||
"\n",
|
||||
@@ -1724,10 +1690,19 @@
|
||||
"batch_predict_job.delete()\n",
|
||||
"\n",
|
||||
"# Delete artifact repository\n",
|
||||
"! gcloud artifacts repositories delete $REPOSITORY --location=$REGION --quiet\n",
|
||||
"! gcloud artifacts repositories delete $REPOSITORY --location=$LOCATION --quiet\n",
|
||||
"\n",
|
||||
"if delete_bucket or os.getenv(\"IS_TESTING\"):\n",
|
||||
" ! gsutil rm -r $BUCKET_URI"
|
||||
"# Delete Cloud Storage objects that were created\n",
|
||||
"delete_bucket = False # Set True for deletion\n",
|
||||
"if delete_bucket:\n",
|
||||
" ! gsutil -m rm -r $BUCKET_URI\n",
|
||||
"\n",
|
||||
"# remove the local users and movies avro files\n",
|
||||
"! rm -rf custom\n",
|
||||
"! rm -f custom.tar.gz\n",
|
||||
"! rm tmp.jpg\n",
|
||||
"! rm tmp1.jpg\n",
|
||||
"! rm tmp2.jpg"
|
||||
]
|
||||
}
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user