-
Notifications
You must be signed in to change notification settings - Fork 19.6k
numpy.meshgrid implementation #21292
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,5 @@ examples/**/*.jpg | |
.python-version | ||
.coverage | ||
*coverage.xml | ||
.ruff_cache | ||
.ruff_cache | ||
keras_venv/ | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,14 +59,8 @@ def __init__(self, factor=0.5, data_format=None, seed=None, **kwargs): | |
def get_random_transformation(self, images, training=True, seed=None): | ||
if seed is None: | ||
seed = self._get_seed_generator(self.backend._backend) | ||
# Base case: Unbatched data | ||
batch_size = 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems unrelated, revert |
||
if len(images.shape) == 4: | ||
# This is a batch of images (4D input) | ||
batch_size = self.backend.core.shape(images)[0] | ||
|
||
random_values = self.backend.random.uniform( | ||
shape=(batch_size,), | ||
shape=(self.backend.core.shape(images)[0],), | ||
minval=0, | ||
maxval=1, | ||
seed=seed, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,37 +78,17 @@ def test_tf_data_compatibility(self): | |
|
||
def test_grayscale_with_single_color_image(self): | ||
test_cases = [ | ||
# batched inputs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems unrelated, revert |
||
(np.full((1, 4, 4, 3), 128, dtype=np.float32), "channels_last"), | ||
(np.full((1, 3, 4, 4), 128, dtype=np.float32), "channels_first"), | ||
# unbatched inputs | ||
(np.full((4, 4, 3), 128, dtype=np.float32), "channels_last"), | ||
(np.full((3, 4, 4), 128, dtype=np.float32), "channels_first"), | ||
] | ||
|
||
for xs, data_format in test_cases: | ||
layer = layers.RandomGrayscale(factor=1.0, data_format=data_format) | ||
transformed = ops.convert_to_numpy(layer(xs)) | ||
|
||
# Determine if the input was batched | ||
is_batched = len(xs.shape) == 4 | ||
|
||
# If batched, select the first image from the batch for inspection. | ||
# Otherwise, use the transformed image directly. | ||
# `image_to_inspect` will always be a 3D tensor. | ||
if is_batched: | ||
image_to_inspect = transformed[0] | ||
else: | ||
image_to_inspect = transformed | ||
|
||
if data_format == "channels_last": | ||
# image_to_inspect has shape (H, W, C), | ||
# get the first channel [:, :, 0] | ||
channel_data = image_to_inspect[:, :, 0] | ||
else: # data_format == "channels_first" | ||
# image_to_inspect has shape (C, H, W), | ||
# get the first channel [0, :, :] | ||
channel_data = image_to_inspect[0, :, :] | ||
|
||
unique_vals = np.unique(channel_data) | ||
self.assertEqual(len(unique_vals), 1) | ||
unique_vals = np.unique(transformed[0, :, :, 0]) | ||
self.assertEqual(len(unique_vals), 1) | ||
else: | ||
unique_vals = np.unique(transformed[0, 0, :, :]) | ||
self.assertEqual(len(unique_vals), 1) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[pytest] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this file |
||
env = | ||
KERAS_BACKEND=openvino |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Undo this, this is very specific to your local setup