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

Added docstring ops/image/resize #509

Merged
merged 5 commits into from
Jul 17, 2023
Merged
Changes from 3 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
30 changes: 29 additions & 1 deletion keras_core/ops/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,35 @@ def compute_output_spec(self, image):
def resize(
image, size, method="bilinear", antialias=False, data_format="channels_last"
):
# TODO: add docstring
"""Resize images to size using the specified method.

Args:
image: Input image or batch of images. Must be 3D or 4D.
size: Size of output image in (height, width) format.
Frightera marked this conversation as resolved.
Show resolved Hide resolved
method: Interpolation method. Defaults to 'bilinear'.
Frightera marked this conversation as resolved.
Show resolved Hide resolved
antialias: Whether to use an antialiasing filter when downsampling an
image.
data_format: Format of the image tensor. Defaults to 'channels_last'.
Frightera marked this conversation as resolved.
Show resolved Hide resolved

Returns:
Resized image or batch of images.

Examples:

>>> x = np.random.random((2, 4, 4, 3)) # batch of 2 RGB images
>>> y = keras_core.ops.image.resize(x, (2, 2))
>>> y.shape
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Print shape (same below)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That depends on the backend, if it is TensorFlow it'll output TensorShape etc. Guess it is best to remove y.shape then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it OK to put symbolic outputs here, like: (2, 2, 2, 3) etc?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it should just be indicative.


>>> x = np.random.random((4, 4, 3)) # single RGB image
>>> y = keras_core.ops.image.resize(x, (2, 2))
>>> y.shape

>>> x = np.random.random((2, 3, 4, 4)) # batch of 2 RGB images
>>> y = keras_core.ops.image.resize(x, (2, 2),
... data_format='channels_first')
Frightera marked this conversation as resolved.
Show resolved Hide resolved
>>> y.shape
"""

if any_symbolic_tensors((image,)):
return Resize(
size, method=method, antialias=antialias, data_format=data_format
Expand Down