在GCP机器学习中,我正在尝试运行培训工作,并将中间输出输出到.csv文件。我正在使用Python中的TensorFlow。
这是我到目前为止尝试的:
1。
with open('gs://<bucket>/<file>', 'wt') as csv_file:
...抛出异常: IOError: [Errno 2] No such file or directory
2。
gcs_file = gcs.open(filename,
'w',
content_type='text/plain',
options={'x-goog-meta-foo': 'foo',
'x-goog-meta-bar': 'bar'},
retry_params=write_retry_params)
gcs_file.write('abcden')
gcs_file.write('f'*1024*4 + 'n')
gcs_file.close()
...抛出异常from google.appengine.api import app_identity ImportError: No module named appengine.api
有什么想法?
对于选项(1),如果您使用的是TensorFlow,则可以使用tf.gfile.Open("gs://...", mode="w")
在GC中打开文件进行写作。
tf.gfile
模块使用TensorFlow的C I/O层,其中包括用于阅读和写入GC的支持。内置Python open()
功能仅在本地文件系统中打开文件。
看起来您正在为应用程序引擎环境编写代码,但是您确定这是编写代码的正确环境吗?
如果您使用的是常规GCP实例,则可能应该使用其他API之一。
from google.cloud import storage
def upload_blob(bucket_name, source_file_name, destination_blob_name):
"""Uploads a file to the bucket."""
storage_client = storage.Client()
bucket = storage_client.get_bucket(bucket_name)
blob = bucket.blob(destination_blob_name)
blob.upload_from_filename(source_file_name)
print('File {} uploaded to {}.'.format(
source_file_name,
destination_blob_name))
编辑:替换API链接