无法从 Cloud ML Engine 中的训练器应用程序下载 Google 云存储文件
Unable to download Google Cloud Storage file from the trainer application in Cloud ML Engine
我正在尝试通过我在 Cloud ML 引擎中运行的训练应用程序从 Cloud Storage 下载文件。但是,当我尝试下载文件时出现以下错误。
我确实有权访问云存储路径。
错误:
blob.download_to_filename(destination_file_name) File "/root/.local/lib/python2.7/site-packages/google/cloud/storage/blob.py", line 482, in download_to_filename self.download_to_file(file_obj, client=client) File "/root/.local/lib/python2.7/site-packages/google/cloud/storage/blob.py", line 464, in download_to_file self._do_download(transport, file_obj, download_url, headers) File "/root/.local/lib/python2.7/site-packages/google/cloud/storage/blob.py", line 418, in _do_download download.consume(transport) File "/root/.local/lib/python2.7/site-packages/google/resumable_media/requests/download.py", line 101, in consume self._write_to_stream(result) File "/root/.local/lib/python2.7/site-packages/google/resumable_media/requests/download.py", line 62, in _write_to_stream with response: AttributeError: __exit__
这是下载 GCS 文件的代码:
storage_client = storage.Client()
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(key)
blob.download_to_filename(destination_file_name)
我没有向 Client
提供任何 GCP 凭据,因为培训应用程序 运行 可以使用
访问其他文件
tf.train.string_input_producer
如有任何帮助,我们将不胜感激。
训练器应用程序通过 TensorFlow 访问其他文件file_io module. 有一些提示,但是如果你想打开一个文件:
with file_io.FileIO("gs://my_bucket/myfile") as f:
f.read()
还有一个 copy(..)
函数和 read_file_to_string(...)
,如果它们更符合您的需求。
我正在尝试通过我在 Cloud ML 引擎中运行的训练应用程序从 Cloud Storage 下载文件。但是,当我尝试下载文件时出现以下错误。 我确实有权访问云存储路径。
错误:
blob.download_to_filename(destination_file_name) File "/root/.local/lib/python2.7/site-packages/google/cloud/storage/blob.py", line 482, in download_to_filename self.download_to_file(file_obj, client=client) File "/root/.local/lib/python2.7/site-packages/google/cloud/storage/blob.py", line 464, in download_to_file self._do_download(transport, file_obj, download_url, headers) File "/root/.local/lib/python2.7/site-packages/google/cloud/storage/blob.py", line 418, in _do_download download.consume(transport) File "/root/.local/lib/python2.7/site-packages/google/resumable_media/requests/download.py", line 101, in consume self._write_to_stream(result) File "/root/.local/lib/python2.7/site-packages/google/resumable_media/requests/download.py", line 62, in _write_to_stream with response: AttributeError: __exit__
这是下载 GCS 文件的代码:
storage_client = storage.Client()
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(key)
blob.download_to_filename(destination_file_name)
我没有向 Client
提供任何 GCP 凭据,因为培训应用程序 运行 可以使用
tf.train.string_input_producer
如有任何帮助,我们将不胜感激。
训练器应用程序通过 TensorFlow 访问其他文件file_io module.
with file_io.FileIO("gs://my_bucket/myfile") as f:
f.read()
还有一个 copy(..)
函数和 read_file_to_string(...)
,如果它们更符合您的需求。