【问题标题】:Loading images in cloud ml在云 ml 中加载图像
【发布时间】:2018-10-21 22:16:59
【问题描述】:

这是在 CPU 机器上工作的主要代码。它从文件夹中加载所有图像和蒙版,调整它们的大小,并保存为 2 个 numpy 数组。

from skimage.transform import resize as imresize
from skimage.io import imread


def create_data(dir_input, img_size):

    img_files = sorted(glob(dir_input + '/images/*.jpg'))
    mask_files = sorted(glob(dir_input + '/masks/*.png'))

    X = []
    Y = []

    for img_path, mask_path in zip(img_files, mask_files):

        img = imread(img_path)
        img = imresize(img, (img_size, img_size), mode='reflect', anti_aliasing=True)

        mask = imread(mask_path)
        mask = imresize(mask, (img_size, img_size), mode='reflect', anti_aliasing=True)

        X.append(img)
        Y.append(mask)



    path_x = dir_input + '/images-{}.npy'.format(img_size)
    path_y = dir_input + '/masks-{}.npy'.format(img_size)

    np.save(path_x, np.array(X))
    np.save(path_y, np.array(Y))


这是 gcloud 存储层次结构

gs://my_bucket
|
|----inputs    
|      |----images/
|      |-----masks/
|   
|----outputs
|
|----trainer    


dir_input 应该是gs://my_bucket/inputs

这不起作用。从云上的该路径加载图像并将 numpy 数组保存在输入文件夹中的正确方法是什么?

最好用skimage,在setup.py中加载

【问题讨论】:

    标签: google-cloud-platform google-cloud-ml


    【解决方案1】:

    大多数 Python 库(例如 numpy)本身并不支持读取和写入 GCS 或 S3 等对象存储。有几个选项:

    • 先将数据复制到本地磁盘(见this answer)。
    • 尝试使用 GCS python SDK (docs)
    • 使用另一个库,例如 TensorFlow 的 FileIO 抽象。 Here's some code 类似于您正在尝试做的事情(读/写 numpy 数组)。

    后者在您使用 TensorFlow 时特别有用,但即使您使用其他一些框架仍然可以使用。

    【讨论】:

      猜你喜欢
      • 2020-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-18
      • 2015-10-13
      • 2020-03-23
      相关资源
      最近更新 更多