Search code examples
google-cloud-vertex-ai

How do I retrieve a model in Vertex AI?


I defined a training job:

job = aiplatform.AutoMLTextTrainingJob(...

then I created a model by running the job:

model = job.run(...

It worked fine but it is now the next day and the variable model was in a Jupyter notebook and no longer exists. I have tried to get it back with:

from google.cloud import aiplatform_v1beta1

def sample_get_model():
    client = aiplatform_v1beta1.ModelServiceClient()

    model_id=id_of_training_pipeline
    name= f'projects/{PROJECT}/locations/{REGION}/models/{model_id}'
    
    request = aiplatform_v1beta1.GetModelRequest(name=name)
    response = client.get_model(request=request)
    print(response)

sample_get_model()

I have also tried the id of v1 of the model created in place of id_of_training_pipeline and I have tried /pipelines/pipeline_id

but I get: E0805 15:12:36.784008212 28406 hpack_parser.cc:1234] Error parsing metadata: error=invalid value key=content-type value=text/html; charset=UTF-8

(PROJECT and REGION are set correctly).


Solution

  • Found this Google code which works.