【问题标题】:Understanding `width_shift_range` and `height_shift_range` arguments in Keras's ImageDataGenerator class理解 Keras 的 ImageDataGenerator 类中的 `width_shift_range` 和 `height_shift_range` 参数
【发布时间】:2020-10-10 13:17:33
【问题描述】:

ImageDataGenerator class 的 Keras 文档说——

width_shift_range: 浮点型、一维数组或整数 - 浮点:总宽度的分数,如果 = 1。 - 一维数组:随机数组中的元素。 - int:来自区间(-width_shift_range, +width_shift_range) 的整数像素数 - 对于width_shift_range=2,可能的值是整数[-1, 0, +1],与width_shift_range=[-1, 0, +1] 相同,而对于width_shift_range=1.0,可能的值是区间[-1.0, +1.0 中的浮点数)。

height_shift_range: 浮点型、一维数组或整数 - 浮点:总高度的分数,如果 = 1。 - 一维数组:随机数组中的元素。 - int:来自区间(-height_shift_range, +height_shift_range) 的整数像素数 - 对于height_shift_range=2,可能的值是整数[-1, 0, +1],与height_shift_range=[-1, 0, +1] 相同,而对于height_shift_range=1.0,可能的值是区间[-1.0, +1.0 )。

我是 Keras 和机器学习的新手,我刚刚开始学习它。

我很难理解 Keras ImageDataGenerator class 的这两个参数的文档和使用,分别命名为 width_shift_rangeheight_shift_range。我搜索了很多,但除了官方之外找不到任何好的文档。这两个论点究竟是做什么的?什么时候必须使用它们?

这个谈话在这里可能看起来不合适,但由于互联网上没有任何讨论,我认为在这里进行讨论会很好。

如果有人帮助我理解这些,我将不胜感激。非常感谢。

【问题讨论】:

  • 这是一个好问题,别担心 :)

标签: python python-3.x machine-learning keras data-generation


【解决方案1】:

ImageDataGenerator class 使用的这两个参数用于在将图像输入网络之前对其进行预处理。如果你想让你的模型更健壮,那么少量的数据是不够的。这就是数据增强派上用场的地方。这用于生成随机数据。

width_shift_range:它实际上将图像向左或向右移动(水平移动)。如果值为float and <=1,它将以总宽度的百分比作为范围。假设图像width is 100px。如果width_shift_range = 1.0 将采用-100% to +100% 表示-100px to +100px。它将在此范围之间随机移动图像。随机选择的正值会将图像移到右侧,负值会将图像移到左侧。我们也可以通过选择像素来做到这一点。 如果我们设置width_shift_range = 100 会产生同样的效果。更重要的是integer value>=1 count pixel as rangefloat value<=1 count percentage of total width as range。下图为width_shift_range = 1.0

height_shift_range: 它与width_shift_range 相同,但垂直移动(向上或向下)。下图为height_shift_range=0.2,fill_mode="constant"

fill_mode:它为输入区域中新移动的像素设置规则。

## fill_mode: One of {"constant", "nearest", "reflect" or "wrap"}. 
## Points outside the boundaries of the input are filled according to the given mode:
## "constant": kkkkkkkk|abcd|kkkkkkkk (cval=k)
## "nearest":  aaaaaaaa|abcd|dddddddd
## "reflect":  abcddcba|abcd|dcbaabcd
## "wrap":  abcdabcd|abcd|abcdabcd

更多信息可以查看blog

【讨论】:

    猜你喜欢
    • 2019-03-24
    • 2021-05-30
    • 1970-01-01
    • 2018-08-07
    • 2017-10-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-05
    相关资源
    最近更新 更多