繁体   English   中英

Google AI 平台无法写入 Cloud Storage

[英]Google AI platform can't write to Cloud Storage

在 Google AI Platform 上运行一个tensorflow-cloud作业,作业的入口点如下:

import tensorflow as tf

filename = r'gs://my_bucket_name/hello.txt'
with tf.io.gfile.GFile(filename, mode='w') as w:
  w.write("Hello, world!")

with tf.io.gfile.GFile(filename, mode='r') as r:
  print(r.read())

作业成功完成,在日志中打印“hello world”。

桶和工作都在同一个区域。

但是我在云存储中找不到该文件。 它不在那里。 我运行了一些其他测试,在那里我做了tf.io.gfile.listdir然后写了一个新文件并再次tf.io.gfile.listdir ,我打印了之前和之后,似乎添加了一个文件但是当我打开云时存储,我在那里找不到它。 还能够从存储中读取文件。

我没有收到任何权限错误,正如官方文档所说,AI Platform 已经具有读取/写入 Cloud Storage 的权限。

这是我的main.py文件:

import tensorflow_cloud as tfc

tfc.run(
   entry_point="run_me.py",
   requirements_txt="requirements.txt",
   chief_config=tfc.COMMON_MACHINE_CONFIGS['CPU'],
   docker_config=tfc.DockerConfig(
      image_build_bucket="test_ai_storage"),
)

这是我可以重现问题的最小版本。

Cloud Storage 不是文件系统。 考虑到这一点,您可以在存储桶中执行上传下载删除操作。

您要做的是打开一个文件并写入其中。 您应该做的是在本地创建文件,然后将其上传到您想要的存储桶。

from google.cloud import storage


def upload_blob(bucket_name, source_file_name, destination_blob_name):
    """Uploads a file to the bucket."""
    # bucket_name = "your-bucket-name"
    # source_file_name = "local/path/to/file"
    # destination_blob_name = "storage-object-name"

    storage_client = storage.Client()
    bucket = storage_client.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
        )
    )

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM