Skip to content

Commit 3943725

Browse files
NicolasHugdatumbox
authored andcommitted
[fbsync] Fix io docs and expose ImageReadMode in torchvision.io (#3812)
Summary: * Fix io imports and expose methods * fix fmt Reviewed By: cpuhrsch Differential Revision: D28538767 fbshipit-source-id: 7e7d11f0267dfcf3e30196256951e732925902b1 Co-authored-by: Vasilis Vryniotis <[email protected]>
1 parent 26f5318 commit 3943725

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

docs/source/io.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,24 @@ Example of inspecting a video:
5959
Image
6060
-----
6161

62+
.. autoclass:: ImageReadMode
63+
6264
.. autofunction:: read_image
6365

6466
.. autofunction:: decode_image
6567

6668
.. autofunction:: encode_jpeg
6769

70+
.. autofunction:: decode_jpeg
71+
6872
.. autofunction:: write_jpeg
6973

7074
.. autofunction:: encode_png
7175

76+
.. autofunction:: decode_png
77+
7278
.. autofunction:: write_png
79+
80+
.. autofunction:: read_file
81+
82+
.. autofunction:: write_file

torchvision/io/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
write_video,
1818
)
1919
from .image import (
20+
ImageReadMode,
2021
decode_image,
2122
decode_jpeg,
2223
decode_png,
@@ -186,6 +187,7 @@ def set_current_stream(self, stream: str):
186187
"_read_video_meta_data",
187188
"VideoMetaData",
188189
"Timebase",
190+
"ImageReadMode",
189191
"decode_image",
190192
"decode_jpeg",
191193
"decode_png",

torchvision/io/image.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ class ImageReadMode(Enum):
5252
"""
5353
Support for various modes while reading images.
5454
55-
Use `ImageReadMode.UNCHANGED` for loading the image as-is,
56-
`ImageReadMode.GRAY` for converting to grayscale,
57-
`ImageReadMode.GRAY_ALPHA` for grayscale with transparency,
58-
`ImageReadMode.RGB` for RGB and `ImageReadMode.RGB_ALPHA` for
55+
Use ``ImageReadMode.UNCHANGED`` for loading the image as-is,
56+
``ImageReadMode.GRAY`` for converting to grayscale,
57+
``ImageReadMode.GRAY_ALPHA`` for grayscale with transparency,
58+
``ImageReadMode.RGB`` for RGB and ``ImageReadMode.RGB_ALPHA`` for
5959
RGB with transparency.
6060
"""
6161
UNCHANGED = 0
@@ -102,7 +102,7 @@ def decode_png(input: torch.Tensor, mode: ImageReadMode = ImageReadMode.UNCHANGE
102102
input (Tensor[1]): a one dimensional uint8 tensor containing
103103
the raw bytes of the PNG image.
104104
mode (ImageReadMode): the read mode used for optionally
105-
converting the image. Default: `ImageReadMode.UNCHANGED`.
105+
converting the image. Default: ``ImageReadMode.UNCHANGED``.
106106
See `ImageReadMode` class for more information on various
107107
available modes.
108108
@@ -120,7 +120,7 @@ def encode_png(input: torch.Tensor, compression_level: int = 6) -> torch.Tensor:
120120
121121
Args:
122122
input (Tensor[channels, image_height, image_width]): int8 image tensor of
123-
`c` channels, where `c` must 3 or 1.
123+
``c`` channels, where ``c`` must 3 or 1.
124124
compression_level (int): Compression factor for the resulting file, it must be a number
125125
between 0 and 9. Default: 6
126126
@@ -139,7 +139,7 @@ def write_png(input: torch.Tensor, filename: str, compression_level: int = 6):
139139
140140
Args:
141141
input (Tensor[channels, image_height, image_width]): int8 image tensor of
142-
`c` channels, where `c` must be 1 or 3.
142+
``c`` channels, where ``c`` must be 1 or 3.
143143
filename (str): Path to save the image.
144144
compression_level (int): Compression factor for the resulting file, it must be a number
145145
between 0 and 9. Default: 6
@@ -160,8 +160,8 @@ def decode_jpeg(input: torch.Tensor, mode: ImageReadMode = ImageReadMode.UNCHANG
160160
the raw bytes of the JPEG image. This tensor must be on CPU,
161161
regardless of the ``device`` parameter.
162162
mode (ImageReadMode): the read mode used for optionally
163-
converting the image. Default: `ImageReadMode.UNCHANGED`.
164-
See `ImageReadMode` class for more information on various
163+
converting the image. Default: ``ImageReadMode.UNCHANGED``.
164+
See ``ImageReadMode`` class for more information on various
165165
available modes.
166166
device (str or torch.device): The device on which the decoded image will
167167
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:
186186
187187
Args:
188188
input (Tensor[channels, image_height, image_width])): int8 image tensor of
189-
`c` channels, where `c` must be 1 or 3.
189+
``c`` channels, where ``c`` must be 1 or 3.
190190
quality (int): Quality of the resulting JPEG file, it must be a number between
191191
1 and 100. Default: 75
192192
@@ -207,8 +207,8 @@ def write_jpeg(input: torch.Tensor, filename: str, quality: int = 75):
207207
Takes an input tensor in CHW layout and saves it in a JPEG file.
208208
209209
Args:
210-
input (Tensor[channels, image_height, image_width]): int8 image tensor of `c`
211-
channels, where `c` must be 1 or 3.
210+
input (Tensor[channels, image_height, image_width]): int8 image tensor of ``c``
211+
channels, where ``c`` must be 1 or 3.
212212
filename (str): Path to save the image.
213213
quality (int): Quality of the resulting JPEG file, it must be a number
214214
between 1 and 100. Default: 75
@@ -229,8 +229,8 @@ def decode_image(input: torch.Tensor, mode: ImageReadMode = ImageReadMode.UNCHAN
229229
input (Tensor): a one dimensional uint8 tensor containing the raw bytes of the
230230
PNG or JPEG image.
231231
mode (ImageReadMode): the read mode used for optionally converting the image.
232-
Default: `ImageReadMode.UNCHANGED`.
233-
See `ImageReadMode` class for more information on various
232+
Default: ``ImageReadMode.UNCHANGED``.
233+
See ``ImageReadMode`` class for more information on various
234234
available modes.
235235
236236
Returns:
@@ -249,8 +249,8 @@ def read_image(path: str, mode: ImageReadMode = ImageReadMode.UNCHANGED) -> torc
249249
Args:
250250
path (str): path of the JPEG or PNG image.
251251
mode (ImageReadMode): the read mode used for optionally converting the image.
252-
Default: `ImageReadMode.UNCHANGED`.
253-
See `ImageReadMode` class for more information on various
252+
Default: ``ImageReadMode.UNCHANGED``.
253+
See ``ImageReadMode`` class for more information on various
254254
available modes.
255255
256256
Returns:

0 commit comments

Comments
 (0)