Unverified Commit 6374cff2 authored by Aditya Oke's avatar Aditya Oke Committed by GitHub
Browse files

Fix io docs and expose `ImageReadMode` in `torchvision.io` (#3812)



* Fix io imports and expose methods

* fix fmt
Co-authored-by: default avatarVasilis Vryniotis <datumbox@users.noreply.github.com>
parent 43d77206
...@@ -59,14 +59,24 @@ Example of inspecting a video: ...@@ -59,14 +59,24 @@ Example of inspecting a video:
Image Image
----- -----
.. autoclass:: ImageReadMode
.. autofunction:: read_image .. autofunction:: read_image
.. autofunction:: decode_image .. autofunction:: decode_image
.. autofunction:: encode_jpeg .. autofunction:: encode_jpeg
.. autofunction:: decode_jpeg
.. autofunction:: write_jpeg .. autofunction:: write_jpeg
.. autofunction:: encode_png .. autofunction:: encode_png
.. autofunction:: decode_png
.. autofunction:: write_png .. autofunction:: write_png
.. autofunction:: read_file
.. autofunction:: write_file
...@@ -17,6 +17,7 @@ from .video import ( ...@@ -17,6 +17,7 @@ from .video import (
write_video, write_video,
) )
from .image import ( from .image import (
ImageReadMode,
decode_image, decode_image,
decode_jpeg, decode_jpeg,
decode_png, decode_png,
...@@ -186,6 +187,7 @@ __all__ = [ ...@@ -186,6 +187,7 @@ __all__ = [
"_read_video_meta_data", "_read_video_meta_data",
"VideoMetaData", "VideoMetaData",
"Timebase", "Timebase",
"ImageReadMode",
"decode_image", "decode_image",
"decode_jpeg", "decode_jpeg",
"decode_png", "decode_png",
......
...@@ -52,10 +52,10 @@ class ImageReadMode(Enum): ...@@ -52,10 +52,10 @@ class ImageReadMode(Enum):
""" """
Support for various modes while reading images. Support for various modes while reading images.
Use `ImageReadMode.UNCHANGED` for loading the image as-is, Use ``ImageReadMode.UNCHANGED`` for loading the image as-is,
`ImageReadMode.GRAY` for converting to grayscale, ``ImageReadMode.GRAY`` for converting to grayscale,
`ImageReadMode.GRAY_ALPHA` for grayscale with transparency, ``ImageReadMode.GRAY_ALPHA`` for grayscale with transparency,
`ImageReadMode.RGB` for RGB and `ImageReadMode.RGB_ALPHA` for ``ImageReadMode.RGB`` for RGB and ``ImageReadMode.RGB_ALPHA`` for
RGB with transparency. RGB with transparency.
""" """
UNCHANGED = 0 UNCHANGED = 0
...@@ -102,7 +102,7 @@ def decode_png(input: torch.Tensor, mode: ImageReadMode = ImageReadMode.UNCHANGE ...@@ -102,7 +102,7 @@ def decode_png(input: torch.Tensor, mode: ImageReadMode = ImageReadMode.UNCHANGE
input (Tensor[1]): a one dimensional uint8 tensor containing input (Tensor[1]): a one dimensional uint8 tensor containing
the raw bytes of the PNG image. the raw bytes of the PNG image.
mode (ImageReadMode): the read mode used for optionally 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 See `ImageReadMode` class for more information on various
available modes. available modes.
...@@ -120,7 +120,7 @@ def encode_png(input: torch.Tensor, compression_level: int = 6) -> torch.Tensor: ...@@ -120,7 +120,7 @@ def encode_png(input: torch.Tensor, compression_level: int = 6) -> torch.Tensor:
Args: Args:
input (Tensor[channels, image_height, image_width]): int8 image tensor of 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 compression_level (int): Compression factor for the resulting file, it must be a number
between 0 and 9. Default: 6 between 0 and 9. Default: 6
...@@ -139,7 +139,7 @@ def write_png(input: torch.Tensor, filename: str, compression_level: int = 6): ...@@ -139,7 +139,7 @@ def write_png(input: torch.Tensor, filename: str, compression_level: int = 6):
Args: Args:
input (Tensor[channels, image_height, image_width]): int8 image tensor of 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. filename (str): Path to save the image.
compression_level (int): Compression factor for the resulting file, it must be a number compression_level (int): Compression factor for the resulting file, it must be a number
between 0 and 9. Default: 6 between 0 and 9. Default: 6
...@@ -160,8 +160,8 @@ def decode_jpeg(input: torch.Tensor, mode: ImageReadMode = ImageReadMode.UNCHANG ...@@ -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, the raw bytes of the JPEG image. This tensor must be on CPU,
regardless of the ``device`` parameter. regardless of the ``device`` parameter.
mode (ImageReadMode): the read mode used for optionally 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 See ``ImageReadMode`` class for more information on various
available modes. available modes.
device (str or torch.device): The device on which the decoded image will 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 be stored. If a cuda device is specified, the image will be decoded
...@@ -186,7 +186,7 @@ def encode_jpeg(input: torch.Tensor, quality: int = 75) -> torch.Tensor: ...@@ -186,7 +186,7 @@ def encode_jpeg(input: torch.Tensor, quality: int = 75) -> torch.Tensor:
Args: Args:
input (Tensor[channels, image_height, image_width])): int8 image tensor of 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 quality (int): Quality of the resulting JPEG file, it must be a number between
1 and 100. Default: 75 1 and 100. Default: 75
...@@ -207,8 +207,8 @@ def write_jpeg(input: torch.Tensor, filename: str, quality: int = 75): ...@@ -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. Takes an input tensor in CHW layout and saves it in a JPEG file.
Args: Args:
input (Tensor[channels, image_height, image_width]): int8 image tensor of `c` input (Tensor[channels, image_height, image_width]): int8 image tensor of ``c``
channels, where `c` must be 1 or 3. channels, where ``c`` must be 1 or 3.
filename (str): Path to save the image. filename (str): Path to save the image.
quality (int): Quality of the resulting JPEG file, it must be a number quality (int): Quality of the resulting JPEG file, it must be a number
between 1 and 100. Default: 75 between 1 and 100. Default: 75
...@@ -229,8 +229,8 @@ def decode_image(input: torch.Tensor, mode: ImageReadMode = ImageReadMode.UNCHAN ...@@ -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 input (Tensor): a one dimensional uint8 tensor containing the raw bytes of the
PNG or JPEG image. PNG or JPEG image.
mode (ImageReadMode): the read mode used for optionally converting the image. mode (ImageReadMode): the read mode used for optionally converting the image.
Default: `ImageReadMode.UNCHANGED`. Default: ``ImageReadMode.UNCHANGED``.
See `ImageReadMode` class for more information on various See ``ImageReadMode`` class for more information on various
available modes. available modes.
Returns: Returns:
...@@ -249,8 +249,8 @@ def read_image(path: str, mode: ImageReadMode = ImageReadMode.UNCHANGED) -> torc ...@@ -249,8 +249,8 @@ def read_image(path: str, mode: ImageReadMode = ImageReadMode.UNCHANGED) -> torc
Args: Args:
path (str): path of the JPEG or PNG image. path (str): path of the JPEG or PNG image.
mode (ImageReadMode): the read mode used for optionally converting the image. mode (ImageReadMode): the read mode used for optionally converting the image.
Default: `ImageReadMode.UNCHANGED`. Default: ``ImageReadMode.UNCHANGED``.
See `ImageReadMode` class for more information on various See ``ImageReadMode`` class for more information on various
available modes. available modes.
Returns: Returns:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment