serving_ml_prediction.ipynb#

Based on:

import os

PROJECT_ID = os.environ.get("GOOGLE_CLOUD_PROJECT")
BUCKET = PROJECT_ID
REGION = 'us-central1'

print(PROJECT_ID)
cloudskillsboost-377709

Create bucket

from google.cloud import storage

storage_client = storage.Client()

bucket = storage_client.bucket(BUCKET)
if not bucket.exists():
    storage_client.create_bucket(BUCKET, location=REGION)

Copy trained model in it

source_bucket_name = 'cloud-training-demos'
path = 'babyweight/trained_model/'

source_bucket = storage_client.bucket(source_bucket_name)

for blob in storage_client.list_blobs(source_bucket, prefix=path):
    source_bucket.copy_blob(blob, bucket, blob.name.replace('/trained_model/', '/'))

Deploy trained model

from google.cloud import aiplatform

endpoint = aiplatform.Model.upload(
    display_name='babyweight',
    artifact_uri=f'gs://{BUCKET}/babyweight/export/exporter/1529355466/',
    serving_container_image_uri='us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-6:latest'
).deploy()
# endpoint.undeploy_all()
# endpoint.delete()