2

Is there a way to directly acquire the model ID from the gcloud ai models upload command?

Either using JSON output or value output, need to manipulate by splitting and extracting. If there is a way to directly get the model ID without manipulation, please advise.

output = !gcloud ai models upload \
  --region=$REGION \
  --display-name=$JOB_NAME \
  --container-image-uri=us-docker.pkg.dev/vertex-ai/prediction/tf2-cpu.2-8:latest \
  --artifact-uri=$GCS_URL_FOR_SAVED_MODEL \
  --format="value(model)"

output
-----
['Using endpoint [https://us-central1-aiplatform.googleapis.com/]',
 'projects/xxxxxxxx/locations/us-central1/models/1961937762277916672',
 'Waiting for operation [8951184153827606528]...',
 '...................................done.']
Ricco D
  • 6,873
  • 1
  • 8
  • 18
mon
  • 18,789
  • 22
  • 112
  • 205

1 Answers1

3

Since you already have values for $REGION and $JOB_NAME, you can use execute gcloud ai models list after you uploaded the model to get the model id with minimal manipulation.

See command below:

export REGION=us-central1
export JOB_NAME=test_training
export PROJECT_ID=your-project-name

gcloud ai models list --region=$REGION --filter="DISPLAY_NAME: $JOB_NAME" | grep "MODEL_ID" | cut -f2 -d: | sed 's/\s//'

Output:

enter image description here


If you want to form the actual string returned by gcloud ai models upload you can just concatenate your variables.

MODEL_ID=$(gcloud ai models list --region=$REGION --filter="DISPLAY_NAME: $JOB_NAME" | grep "MODEL_ID" | cut -f2 -d: | sed 's/\s//')

echo projects/${PROJECT_ID}/locations/${REGION}/models/${MODEL_ID}

Output:

enter image description here

Ricco D
  • 6,873
  • 1
  • 8
  • 18