Create model resource
Section "Deploy the model to AI Platform Prediction", create model resource.
The following code always executes the ELSE part, instead of the IF, which means the resource does NOT get created.
model_name = 'forest_cover_classifier'
labels = "task=classifier,domain=forestry"
filter = 'name:{}'.format(model_name)
models = !(gcloud ai-platform models list --filter={filter} --format='value(name)')
if not models:
!gcloud ai-platform models create $model_name \
--regions=$REGION \
--labels=$labels
else:
print("Model: {} already exists.".format(models[0]))
The reason for this to fail is because the following command
gcloud ai-platform models list
generates the following output:
...@cloudshell:~ (my-project)$ gcloud ai-platform models list
Using endpoint [https://ml.googleapis.com/]
Listed 0 items.
The "Using endpoint…" string passes the filter and therefore the models variable is not none.
models == ['Using endpoint [https://ml.googleapis.com/]']
This cause the ELSE to be execute, therefore no resource is created.
Create model version
Section "Deploy the model to AI Platform Prediction", create model version.
A similar thing happens for creating the version:
model_version = 'v01'
filter = 'name:{}'.format(model_version)
versions = !(gcloud ai-platform versions list --model={model_name} --format='value(name)' --filter={filter})
if not versions:
!gcloud ai-platform versions create {model_version} \
--model={model_name} \
--origin=$JOB_DIR \
--runtime-version=1.15 \
--framework=scikit-learn \
--python-version=3.7
else:
print("Model version: {} already exists.".format(versions[0]))
The version is not created either.