Compare commits

...
Author SHA1 Message Date
Andrew Ferlitsch dc1c7945e1 port: kfp2 2023-10-02 22:28:20 +00:00
@@ -149,8 +149,8 @@
"outputs": [],
"source": [
"! pip3 install --upgrade --quiet google-cloud-aiplatform \\\n",
" 'kfp<2' \\\n",
" 'google-cloud-pipeline-components<2' \\\n",
" kfp \\\n",
" google-cloud-pipeline-components \\\n",
" google-cloud-storage"
]
},
@@ -349,6 +349,17 @@
"Create a storage bucket to store intermediate artifacts such as datasets."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "MzGDU7TWdts_"
},
"outputs": [],
"source": [
"BUCKET_URI = f\"gs://your-bucket-name-{PROJECT_ID}-unique\" # @param {type:\"string\"}"
]
},
{
"cell_type": "markdown",
"metadata": {
@@ -362,11 +373,11 @@
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "MzGDU7TWdts_"
"id": "create_bucket"
},
"outputs": [],
"source": [
"BUCKET_URI = f\"gs://your-bucket-name-{PROJECT_ID}-unique\" # @param {type:\"string\"}"
"! gsutil mb -l {REGION} {BUCKET_URI}"
]
},
{
@@ -399,6 +410,9 @@
},
"outputs": [],
"source": [
"import sys\n",
"\n",
"IS_COLAB = \"google.colab\" in sys.modules\n",
"if (\n",
" SERVICE_ACCOUNT == \"\"\n",
" or SERVICE_ACCOUNT is None\n",
@@ -463,7 +477,7 @@
"\n",
"import google.cloud.aiplatform as aip\n",
"import kfp\n",
"from kfp.v2 import compiler"
"from kfp import compiler"
]
},
{
@@ -485,7 +499,7 @@
},
"outputs": [],
"source": [
"PIPELINE_ROOT = \"{}/pipeline_root/flowers\".format(BUCKET_URI)"
"PIPELINE_ROOT = f\"{BUCKET_URI}/pipeline_root/flowers\""
]
},
{
@@ -533,18 +547,21 @@
"source": [
"@kfp.dsl.pipeline(name=\"automl-image-training-v2\")\n",
"def pipeline(project: str = PROJECT_ID, region: str = REGION):\n",
" from google_cloud_pipeline_components import aiplatform as gcc_aip\n",
" from google_cloud_pipeline_components.v1.automl.training_job import \\\n",
" AutoMLImageTrainingJobRunOp\n",
" from google_cloud_pipeline_components.v1.dataset import \\\n",
" ImageDatasetCreateOp\n",
" from google_cloud_pipeline_components.v1.endpoint import (EndpointCreateOp,\n",
" ModelDeployOp)\n",
"\n",
" ds_op = gcc_aip.ImageDatasetCreateOp(\n",
" ds_op = ImageDatasetCreateOp(\n",
" project=project,\n",
" display_name=\"flowers\",\n",
" gcs_source=\"gs://cloud-samples-data/vision/automl_classification/flowers/all_data_v2.csv\",\n",
" import_schema_uri=aip.schema.dataset.ioformat.image.single_label_classification,\n",
" )\n",
"\n",
" training_job_run_op = gcc_aip.AutoMLImageTrainingJobRunOp(\n",
" training_job_run_op = AutoMLImageTrainingJobRunOp(\n",
" project=project,\n",
" display_name=\"train-automl-flowers\",\n",
" prediction_type=\"classification\",\n",
@@ -591,8 +608,7 @@
"outputs": [],
"source": [
"compiler.Compiler().compile(\n",
" pipeline_func=pipeline,\n",
" package_path=\"image classification_pipeline.json\".replace(\" \", \"_\"),\n",
" pipeline_func=pipeline, package_path=\"image_classification_pipeline.yaml\"\n",
")"
]
},
@@ -619,14 +635,14 @@
"\n",
"job = aip.PipelineJob(\n",
" display_name=DISPLAY_NAME,\n",
" template_path=\"image classification_pipeline.json\".replace(\" \", \"_\"),\n",
" template_path=\"image_classification_pipeline.yaml\",\n",
" pipeline_root=PIPELINE_ROOT,\n",
" enable_caching=False,\n",
")\n",
"\n",
"job.run()\n",
"\n",
"! rm image_classification_pipeline.json"
"! rm image_classification_pipeline.yaml"
]
},
{