在谷歌AI平台上运行一个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平台已经拥有对云存储的读写权限。
这是我的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"),
)这是我可以重现问题的最小版本。
发布于 2020-11-19 06:28:08
云硬盘不是文件系统。记住这一点,您可以在存储桶中执行uploads、downloads或Deletion操作。
您要做的是打开一个文件并写入其中。您应该做的是在本地创建文件,然后将其上传到您想要的存储桶中。
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
)
)https://stackoverflow.com/questions/64837612
复制相似问题