我使用Google Cloud ML-Engine在Python上工作。我发现的文档表明数据存储应该使用Buckets和Blob完成
https://cloud.google.com/ml-engine/docs/tensorflow/working-with-cloud-storage
但是,我的大部分代码和它调用的库都与文件一起使用。我能否以某种方式将Google Storage视为我的ml-engine代码中的文件系统?
我想让我的代码看起来像
with open(<something>) as f:
for line in f:
dosomething(line)
请注意,在ml-engine中,不会创建和配置VM实例。所以我无法用Filestore挂载我自己的共享文件系统。
将云存储作为文件系统显示的唯一方法是mount a bucket as a file system:
您可以使用Google Cloud Storage FUSE工具将云存储桶安装到Compute Engine实例。尽管云存储桶是对象存储,但安装的存储桶的行为与persistent disk类似。
但是,如果无法创建和配置VM,则无法执行此操作。
请注意,在ml-engine中,不会创建和配置VM实例。
这不完全正确。我看到ML Engine支持building custom containers,这通常是如何安装和配置操作系统级别的依赖项。但仅限于培训区域,因此如果您需要在该区域,则可能值得一试。
我假设您已经检查过该库不支持通过已打开的文件类处理程序进行访问(如果没有那么可能感兴趣的是How to restore Tensorflow model from Google bucket without writing to filesystem?)
对于那些后来的人来说,这就是答案
Google Cloud ML and GCS Bucket issues
from tensorflow.python.lib.io import file_io
这是一个例子
with file_io.FileIO("gc://bucket_name/foobar.txt","w") as f:
f.write("FOO")
f.flush()
print("Write foobar.txt")
with file_io.FileIO("gc://bucket_name/foobar.txt","r") as f:
for line in f:
print("Read foobar.txt: "+line)