Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageDataGenerator: Allow specifying width/height_shift_range in pixels #8830

Merged
merged 2 commits into from
Dec 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions keras/preprocessing/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ class ImageDataGenerator(object):
zca_whitening: apply ZCA whitening.
zca_epsilon: epsilon for ZCA whitening. Default is 1e-6.
rotation_range: degrees (0 to 180).
width_shift_range: fraction of total width.
height_shift_range: fraction of total height.
width_shift_range: fraction of total width, if < 1, or pixels if >= 1.
height_shift_range: fraction of total height, if < 1, or pixels if >= 1.
shear_range: shear intensity (shear angle in radians).
zoom_range: amount of zoom. if scalar z, zoom will be randomly picked
in the range [1-z, 1+z]. A sequence of two can be passed instead
Expand Down Expand Up @@ -611,12 +611,16 @@ def random_transform(self, x, seed=None):
theta = 0

if self.height_shift_range:
tx = np.random.uniform(-self.height_shift_range, self.height_shift_range) * x.shape[img_row_axis]
tx = np.random.uniform(-self.height_shift_range, self.height_shift_range)
if self.height_shift_range < 1:
tx *= x.shape[img_row_axis]
else:
tx = 0

if self.width_shift_range:
ty = np.random.uniform(-self.width_shift_range, self.width_shift_range) * x.shape[img_col_axis]
ty = np.random.uniform(-self.width_shift_range, self.width_shift_range)
if self.width_shift_range < 1:
ty *= x.shape[img_col_axis]
else:
ty = 0

Expand Down