Skip to content

Commit

Permalink
Bug fix for TF backend using random zoom with flatten (#18835)
Browse files Browse the repository at this point in the history
* bug fix

* skip the numpy backend
  • Loading branch information
haifeng-jin authored Nov 27, 2023
1 parent 7a65022 commit 9c675a9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions keras/backend/tensorflow/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def affine_transform(
interpolation=interpolation.upper(),
fill_mode=fill_mode.upper(),
)
affined = tf.ensure_shape(affined, image.shape)

if data_format == "channels_first":
affined = tf.transpose(affined, (0, 3, 1, 2))
Expand Down
17 changes: 17 additions & 0 deletions keras/layers/preprocessing/random_zoom_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import pytest
from absl.testing import parameterized
from tensorflow import data as tf_data

Expand Down Expand Up @@ -132,3 +133,19 @@ def test_dynamic_shape(self):
)(inputs)
model = models.Model(inputs, outputs)
model.predict(np.random.random((1, 6, 6, 3)))

@pytest.mark.skipif(
backend.backend() == "numpy",
reason="The NumPy backend does not implement fit.",
)
def test_connect_with_flatten(self):
model = models.Sequential(
[
layers.RandomZoom((-0.5, 0.0), (-0.5, 0.0)),
layers.Flatten(),
layers.Dense(1, activation="relu"),
],
)

model.compile(loss="mse")
model.fit(np.random.random((2, 2, 2, 1)), y=np.random.random((2,)))

0 comments on commit 9c675a9

Please sign in to comment.