我正试图将SavedModel格式的tensorflow模型从我的谷歌云存储桶加载到我的云函数中。我正在使用此教程:https://cloud.google.com/blog/products/ai-machine-learning/how-to-serve-deep-learning-models-using-tensorflow-2-0-with-cloud-functions
cloud函数编译正确。然而,当我向云功能发送http请求时,它会给出以下错误:
追踪(最近一次通话(:
文件"/env/local/lib/python3.7/site packages/google/cloud/functions/worker_v2.py";,第402行,在run_http_function result=_function_handler.invoke_user_function(flack.request(File"中/env/local/lib/python3.7/site packages/google/cloud/functions/worker_v2.py";,在invoke_user_function return call_user_ffunction(request_or_event(File"中的第268行/env/local/lib/python3.7/site packages/google/cloud/functions/worker_v2.py";,第261行,在call_user_function中返回self_user_function(request_or_event(文件"/user_code/main.py";,第29行,在predict-download_blob(","firstModel/saved_model.pb","/tmp/model/saved_model.pb"(文件"/user_code/main.py";,第17行,在download_blob bucket=storage_client.get_bucket(bucket_name(File中"env/local/lib/python3.7/site packages/google/cloud/storage/client.py";,第356行,在get_bucket bucket=self中_bucket_arg_to_bucket(bucket_or_name(文件"env/local/lib/python3.7/site packages/google/cloud/storage/client.py";,第225行,在_bucket_arg_to_bucket bucket=bucket(self,name=bucket_or_name(File"中/env/local/lib/python3.7/site packages/google/cloud/storage/bucket.py";,第581行,在initname=_validate_name(name(File"/env/local/lib/python3.7/site packages/google/cloud/storage/helpers.py";,第67行,_validate_name中的引发ValueError("Bucket名称必须以数字或字母开头和结尾
我很困惑,因为我的水桶的标题是一个大约20个字符长的字母串,没有任何标点符号/特殊字符。
这是我正在运行的一些代码:
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)
错误消息抱怨bucket名称中有尖括号,这些尖括号不被视为数字或字母。确保您的bucket名称与您在云控制台中看到的名称完全相同。