Skip to content

Fix io docs and expose ImageReadMode in torchvision.io #3812

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

Merged
merged 3 commits into from
May 11, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 10 additions & 0 deletions docs/source/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,24 @@ Example of inspecting a video:
Image
-----

.. autoclass:: ImageReadMode

.. autofunction:: read_image

.. autofunction:: decode_image

.. autofunction:: encode_jpeg

.. autofunction:: decode_jpeg

.. autofunction:: write_jpeg

.. autofunction:: encode_png

.. autofunction:: decode_png

.. autofunction:: write_png

.. autofunction:: read_file

.. autofunction:: write_file
2 changes: 2 additions & 0 deletions torchvision/io/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
write_video,
)
from .image import (
ImageReadMode,
decode_image,
decode_jpeg,
decode_png,
Expand Down Expand Up @@ -186,6 +187,7 @@ def set_current_stream(self, stream: str):
"_read_video_meta_data",
"VideoMetaData",
"Timebase",
"ImageReadMode",
"decode_image",
"decode_jpeg",
"decode_png",
Expand Down
32 changes: 16 additions & 16 deletions torchvision/io/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ class ImageReadMode(Enum):
"""
Support for various modes while reading images.

Use `ImageReadMode.UNCHANGED` for loading the image as-is,
`ImageReadMode.GRAY` for converting to grayscale,
`ImageReadMode.GRAY_ALPHA` for grayscale with transparency,
`ImageReadMode.RGB` for RGB and `ImageReadMode.RGB_ALPHA` for
Use ``ImageReadMode.UNCHANGED`` for loading the image as-is,
``ImageReadMode.GRAY`` for converting to grayscale,
``ImageReadMode.GRAY_ALPHA`` for grayscale with transparency,
``ImageReadMode.RGB`` for RGB and ``ImageReadMode.RGB_ALPHA`` for
RGB with transparency.
"""
UNCHANGED = 0
Expand Down Expand Up @@ -102,7 +102,7 @@ def decode_png(input: torch.Tensor, mode: ImageReadMode = ImageReadMode.UNCHANGE
input (Tensor[1]): a one dimensional uint8 tensor containing
the raw bytes of the PNG image.
mode (ImageReadMode): the read mode used for optionally
converting the image. Default: `ImageReadMode.UNCHANGED`.
converting the image. Default: ``ImageReadMode.UNCHANGED``.
See `ImageReadMode` class for more information on various
available modes.

Expand All @@ -120,7 +120,7 @@ def encode_png(input: torch.Tensor, compression_level: int = 6) -> torch.Tensor:

Args:
input (Tensor[channels, image_height, image_width]): int8 image tensor of
`c` channels, where `c` must 3 or 1.
``c`` channels, where ``c`` must 3 or 1.
compression_level (int): Compression factor for the resulting file, it must be a number
between 0 and 9. Default: 6

Expand All @@ -139,7 +139,7 @@ def write_png(input: torch.Tensor, filename: str, compression_level: int = 6):

Args:
input (Tensor[channels, image_height, image_width]): int8 image tensor of
`c` channels, where `c` must be 1 or 3.
``c`` channels, where ``c`` must be 1 or 3.
filename (str): Path to save the image.
compression_level (int): Compression factor for the resulting file, it must be a number
between 0 and 9. Default: 6
Expand All @@ -160,8 +160,8 @@ def decode_jpeg(input: torch.Tensor, mode: ImageReadMode = ImageReadMode.UNCHANG
the raw bytes of the JPEG image. This tensor must be on CPU,
regardless of the ``device`` parameter.
mode (ImageReadMode): the read mode used for optionally
converting the image. Default: `ImageReadMode.UNCHANGED`.
See `ImageReadMode` class for more information on various
converting the image. Default: ``ImageReadMode.UNCHANGED``.
See ``ImageReadMode`` class for more information on various
available modes.
device (str or torch.device): The device on which the decoded image will
be stored. If a cuda device is specified, the image will be decoded
Expand All @@ -186,7 +186,7 @@ def encode_jpeg(input: torch.Tensor, quality: int = 75) -> torch.Tensor:

Args:
input (Tensor[channels, image_height, image_width])): int8 image tensor of
`c` channels, where `c` must be 1 or 3.
``c`` channels, where ``c`` must be 1 or 3.
quality (int): Quality of the resulting JPEG file, it must be a number between
1 and 100. Default: 75

Expand All @@ -207,8 +207,8 @@ def write_jpeg(input: torch.Tensor, filename: str, quality: int = 75):
Takes an input tensor in CHW layout and saves it in a JPEG file.

Args:
input (Tensor[channels, image_height, image_width]): int8 image tensor of `c`
channels, where `c` must be 1 or 3.
input (Tensor[channels, image_height, image_width]): int8 image tensor of ``c``
channels, where ``c`` must be 1 or 3.
filename (str): Path to save the image.
quality (int): Quality of the resulting JPEG file, it must be a number
between 1 and 100. Default: 75
Expand All @@ -229,8 +229,8 @@ def decode_image(input: torch.Tensor, mode: ImageReadMode = ImageReadMode.UNCHAN
input (Tensor): a one dimensional uint8 tensor containing the raw bytes of the
PNG or JPEG image.
mode (ImageReadMode): the read mode used for optionally converting the image.
Default: `ImageReadMode.UNCHANGED`.
See `ImageReadMode` class for more information on various
Default: ``ImageReadMode.UNCHANGED``.
See ``ImageReadMode`` class for more information on various
available modes.

Returns:
Expand All @@ -249,8 +249,8 @@ def read_image(path: str, mode: ImageReadMode = ImageReadMode.UNCHANGED) -> torc
Args:
path (str): path of the JPEG or PNG image.
mode (ImageReadMode): the read mode used for optionally converting the image.
Default: `ImageReadMode.UNCHANGED`.
See `ImageReadMode` class for more information on various
Default: ``ImageReadMode.UNCHANGED``.
See ``ImageReadMode`` class for more information on various
available modes.

Returns:
Expand Down