【问题标题】:How to access images directly from Google Cloud Storage (GCS) when using Keras?使用 Keras 时如何直接从 Google Cloud Storage (GCS) 访问图像?
【发布时间】:2018-09-30 13:32:14
【问题描述】:

我在 Keras 中开发了一个模型,在读取本地存储的数据时可以完美运行。但是,我现在想利用 Google Cloud Platform 的 GPU 来训练模型。我已经在 GCP 上设置了 GPU,并且正在使用 Jupyter 笔记本。我已将图像移至 Google Cloud Storage。

我的问题是:

如何使用 ImageDataGenerator 类的 Keras 的 flow_from_directory 方法直接从 Cloud Storage 访问这些图像(特别是目录 - 训练、验证、测试)?

这是我在 Google Cloud Storage (GCS) 中的目录结构:

mybucketname/
      class_1/
          img001.jpg
          img002.jpg
          ...
      class_2/
          img001.jpg
          img002.jpg
          ...
      class_3/
          img001.jpg 
          img002.jpg
          ...

【问题讨论】:

  • 我发现通过import os, sys os.system('gsutil cp -r gs://mybucketname/ .') 将文件直接从云存储复制到虚拟机可以工作,但这不是我希望的优雅解决方案...
  • 您需要自己的自定义生成器。
  • 看起来从存储桶复制到虚拟机是唯一的方法。 gsutil是最实用的方式,客户端api会多出几行代码。

标签: tensorflow keras google-cloud-platform google-cloud-storage


【解决方案1】:

虽然我还没有找到直接从 GCS 读取图像数据的方法,但同时我可以通过 import os, sys os.system('gsutil cp -r gs://mybucketname/ .') 将文件直接从 Cloud Storage 复制到 VM

【讨论】:

  • 感谢您分享此解决方案!您是否知道同时出现任何允许将文件直接从存储桶加载到ImageDataGenerator.flow_from_directory( directory, ...) 中的目录?我试过输入gs://mybucketname/,但这不起作用。
猜你喜欢
  • 1970-01-01
  • 2018-06-25
  • 1970-01-01
  • 1970-01-01
  • 2019-12-02
  • 2018-06-06
  • 1970-01-01
  • 2012-08-21
  • 2017-07-30
相关资源
最近更新 更多