【问题标题】:Hacky way to augment multichannel images in Keras在 Keras 中增强多通道图像的黑客方法
【发布时间】:2017-01-20 16:35:26
【问题描述】:

我需要增强多通道图像并想使用 ImageDataGenerator 不幸的是,它只支持 1,3 和 4 通道图像,我需要更多。直接编辑 site-packages/Keras/preprocessing/image.py 添加必要数量的频道可以吗?

    if x.shape[self.channel_axis] not in {1, 3, 4, XXX}:
        raise ValueError(
            'Expected input to be images (as Numpy array) '
            'following the dimension ordering convention "' + self.dim_ordering + '" '
            '(channels on axis ' + str(self.channel_axis) + '), i.e. expected '
            'either 1, 3 or 4 channels on axis ' + str(self.channel_axis) + '. '
            'However, it was passed an array with shape ' + str(x.shape) +
            ' (' + str(x.shape[self.channel_axis]) + ' channels).')

其中 XXX - 是我需要的多个频道。这会破坏什么吗? 谢谢!

【问题讨论】:

    标签: python keras


    【解决方案1】:

    无论如何我都试过了,它似乎没有太多副作用。不过,我并没有探索所有可能的问题。因此,如果您有多通道数据(如卫星图像等),您可以尝试这个 hack。有几个地方需要增加扩充代码:)

    【讨论】:

    • 您是如何扩充数据的?您是使用 ImageDataGenerator 还是为此编写了自己的自定义函数?我和你有同样的问题,我需要增加体积数据(MRI 图像)。我的意思是,除了你所做的 hack,你还写过其他自定义函数吗?
    • 嗨,拉古拉姆!不,我单独使用了 ImageDataGenerator。
    • 在编辑和运行文件后,我收到一条错误消息,指出 File "/usr/local/lib/python2.7/dist-packages/keras/preprocessing/image.py", line 446, in flow_from_directory follow_links=follow_links) 文件“/usr/local/lib/python2.7/dist-packages/keras/preprocessing/image.py”,第 777 行,在 init 中,用于 sorted(os. listdir(directory)): OSError: [Errno 2] 没有这样的文件或目录。对此有任何想法吗?
    • 嗨 Raghuram,您是否尝试使用 flow_from_directory 或类似的?我没有使用它,仅将 ImageDataGenerator 用于内存堆栈。
    • 哦,好吧。我认为这让事情变得更清楚了。谢谢你的信息,丹尼斯 :)
    猜你喜欢
    • 2020-05-31
    • 1970-01-01
    • 2022-08-21
    • 1970-01-01
    • 2018-02-24
    • 1970-01-01
    • 2020-03-09
    • 1970-01-01
    • 2023-03-28
    相关资源
    最近更新 更多