I am trying to load a tensorflow model in SavedModel format from my google cloud bucket into my cloud function. I am using this tutorial: https://cloud.google.com/blog/products/ai-machine-learning/how-to-serve-deep-learning-models-using-tensorflow-2-0-with-cloud-functions
The cloud function compiles correctly. However when I send an http request to the cloud function it gives this error:
Traceback (most recent call last):
File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v2.py", line 402, in run_http_function result = _function_handler.invoke_user_function(flask.request) File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v2.py", line 268, in invoke_user_function return call_user_function(request_or_event) File "/env/local/lib/python3.7/site-packages/google/cloud/functions/worker_v2.py", line 261, in call_user_function return self._user_function(request_or_event) File "/user_code/main.py", line 29, in predict download_blob('', 'firstModel/saved_model.pb', '/tmp/model/saved_model.pb') File "/user_code/main.py", line 17, in download_blob bucket = storage_client.get_bucket(bucket_name) File "/env/local/lib/python3.7/site-packages/google/cloud/storage/client.py", line 356, in get_bucket bucket = self._bucket_arg_to_bucket(bucket_or_name) File "/env/local/lib/python3.7/site-packages/google/cloud/storage/client.py", line 225, in _bucket_arg_to_bucket bucket = Bucket(self, name=bucket_or_name) File "/env/local/lib/python3.7/site-packages/google/cloud/storage/bucket.py", line 581, in init name = _validate_name(name) File "/env/local/lib/python3.7/site-packages/google/cloud/storage/_helpers.py", line 67, in _validate_name raise ValueError("Bucket names must start and end with a number or letter.") ValueError: Bucket names must start and end with a number or letter.
I am confused because my buckets' title is a string of letters around 20 characters long without any punctuation/special characters.
This is some of the code that I am running:
if model is None:
download_blob('<terminatorbucket>', 'firstModel/saved_model.pb', '/tmp/model/saved_model.pb')
download_blob('<terminatorbucket>', 'firstModel/assets/tokens.txt', '/tmp/model/assets/tokens.txt')
download_blob('<terminatorbucket>', 'firstModel/variables/variables.index', '/tmp/model/variables/variables.index')
download_blob('<terminatorbucket>', 'firstModel/variables/variables.data-00000-of-00001', '/tmp/model/variables/variables.data-00000-of-00001')
model = tf.keras.models.load_model('/tmp/model')
def download_blob(bucket_name, source_blob_name, destination_file_name):
"""Downloads a blob from the bucket."""
storage_client = storage.Client()
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(source_blob_name)
blob.download_to_filename(destination_file_name)
The error message is complaining about the fact that you have angle brackets in your bucket name, which are not considered numbers or letters. Make sure your bucket name is exactly what you see in the Cloud console.