reese0106
reese0106

Reputation: 2061

Obtain saved_model.pb location for specific GCMLE model from within jupyter notebook

I have a GCMLE model deployed as a model for GCMLE prediction service. In the GCP console UI I can navigate to the model name -> version and then I can view the Model location (ie gs://..../) which specifies the location of my saved_model.pb file. Is there any way to dynamically obtain this "model location" within a jupyter notebook/python script? I would like to be able to then use this model location to download the saved_model.pb locally so that I can load the model into a local session for debugging purposes on specific inference tasks. Currently, I can do all of this manually, but I'd like to be able to quickly flip between model versions without needing to manually track/download the saved_model.pb files.

Upvotes: 0

Views: 41

Answers (1)

rhaertel80
rhaertel80

Reputation: 8389

Issuing a GET request (docs) against your version resource will return a Version object that has the deploymentUri field you are looking for. You can use any library for issuing HTTP request in your language of choice, although you do need to send an authorization token in the headers.

Here's an example in Python:

import requests
from oauth2client.client import GoogleCredentials

token = GoogleCredentials.get_application_default().get_access_token().access_token
api = 'https://ml.googleapis.com/v1/projects/MYPROJECT/models/MYMODEL/versions/MYVERSION'
headers = {'Authorization': 'Bearer ' + token }    
response = requests.get(api, headers=headers)
print response.json()['deploymentUri']

Upvotes: 2

Related Questions