python - 了解Keras的ImageDataGenerator类中的 `width_shift_range`和 `height_shift_range`参数

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

ImageDataGenerator class的Keras文档说:

width_shift_range: Float, 1-D array-like or int - float: fraction of total width, if < 1, or pixels if >= 1. - 1-D array-like: random elements from the array. - int: integer number of pixels from interval (-width_shift_range, +width_shift_range) - With width_shift_range=2 possible values are integers [-1, 0, +1], same as with width_shift_range=[-1, 0, +1], while with width_shift_range=1.0 possible values are floats in the interval [-1.0, +1.0).


height_shift_range: Float, 1-D array-like or int - float: fraction of total height, if < 1, or pixels if >= 1. - 1-D array-like: random elements from the array. - int: integer number of pixels from interval (-height_shift_range, +height_shift_range) - With height_shift_range=2 possible values are integers [-1, 0, +1], same as with height_shift_range=[-1, 0, +1], while with height_shift_range=1.0 possible values are floats in the interval [-1.0, +1.0).


我是Keras和机器学习的新手,我才刚刚开始学习它。
我正在努力了解Keras ImageDataGenerator class 这两个参数width_shift_rangeheight_shift_range的文档和用法。我搜了很多东西,但是除了官方没有找到任何好的文档。这两个参数究竟是做什么的?什么时候必须使用它们?
这里的谈话似乎不合适,但由于互联网上没有任何讨论,因此我认为在这里进行讨论会很好。
如果有人帮助我理解这些,我将不胜感激。非常感谢你。

最佳答案

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的图片。
For value 1
height_shift_range:width_shift_range相同,但垂直(向上或向下)移动。下图是height_shift_range=0.2,fill_mode="constant"的图片
enter image description here
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

关于python - 了解Keras的ImageDataGenerator类中的 `width_shift_range`和 `height_shift_range`参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62484597/

相关文章:

python-2.7 - 如何使用数组有选择地从数据框中复制行?

python - python扭曲静态文件中的变量替换

python - 使用 Python 执行模块化矩阵求逆的最简单方法?

Python登录验证系统

python - Python 中的条件嵌套循环

matlab - RBF 神经网络

python - 致命标志解析错误 :Unknown command line flag 'logtostderr'

python - 如何在循环中读取用户输入(并且不阻塞此循环中的工作)?

python - 在规定时间内完成画圆

machine-learning - 为什么多标签分类(二元相关性)起作用?