Skip to content

Commit

Permalink
Revert keras-team#9025 because it introduces a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloskath committed Jan 26, 2018
1 parent 0478e07 commit b9e7464
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 4 additions & 5 deletions keras/preprocessing/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,11 +748,10 @@ def fit(self, x,

if self.zca_whitening:
flat_x = np.reshape(x, (x.shape[0], x.shape[1] * x.shape[2] * x.shape[3]))
num_examples = flat_x.shape[0]
_, s, vt = linalg.svd(flat_x / np.sqrt(num_examples))
s_expand = np.hstack((s, np.zeros(vt.shape[0] - num_examples,
dtype=flat_x.dtype)))
self.principal_components = (vt.T / np.sqrt(s_expand ** 2 + self.zca_epsilon)).dot(vt)
sigma = np.dot(flat_x.T, flat_x) / flat_x.shape[0]
u, s, _ = linalg.svd(sigma)
s_inv = 1. / np.sqrt(s[np.newaxis] + self.zca_epsilon)
self.principal_components = (u * s_inv).dot(u.T)


class Iterator(Sequence):
Expand Down
6 changes: 6 additions & 0 deletions tests/keras/preprocessing/image_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ def test_image_data_generator_fit(self):
# Test RBG
x = np.random.random((32, 10, 10, 3))
generator.fit(x)
# Test more samples than dims
x = np.random.random((32, 4, 4, 1))
generator.fit(x)
generator = image.ImageDataGenerator(
featurewise_center=True,
samplewise_center=True,
Expand All @@ -136,6 +139,9 @@ def test_image_data_generator_fit(self):
# Test RBG
x = np.random.random((32, 3, 10, 10))
generator.fit(x)
# Test more samples than dims
x = np.random.random((32, 1, 4, 4))
generator.fit(x)

def test_directory_iterator(self, tmpdir):
num_classes = 2
Expand Down

0 comments on commit b9e7464

Please sign in to comment.