2020
2121
2222class  ImageReadMode (Enum ):
23-  """ 
24-  Support for various modes while reading images. 
23+  """Allow automatic conversion to RGB, RGBA, etc while decoding. 
24+ 
25+  .. note:: 
26+ 
27+  You don't need to use this struct, you can just pass strings to all 
28+  ``mode`` parameters, e.g. ``mode="RGB"``. 
2529
26-  Use ``ImageReadMode.UNCHANGED`` for loading the image as-is, 
27-  ``ImageReadMode.GRAY`` for converting to grayscale, 
28-  ``ImageReadMode.GRAY_ALPHA`` for grayscale with transparency, 
29-  ``ImageReadMode.RGB`` for RGB and ``ImageReadMode.RGB_ALPHA`` for 
30-  RGB with transparency. 
30+  The different available modes are the following. 
31+ 
32+  - UNCHANGED: loads the image as-is 
33+  - RGB: converts to RGB 
34+  - RGBA: converts to RGB with transparency (also aliased as RGB_ALPHA) 
35+  - GRAY: converts to grayscale 
36+  - GRAY_ALPHA: converts to grayscale with transparency 
3137
3238 .. note:: 
3339
34-  Some decoders won't support all possible values, e.g. a decoder may only  
35-  support "RGB"  and "RGBA" mode . 
40+  Some decoders won't support all possible values, e.g. GRAY and  
41+  GRAY_ALPHA are only supported for PNG  and JPEG images . 
3642 """ 
3743
3844 UNCHANGED  =  0 
@@ -45,8 +51,7 @@ class ImageReadMode(Enum):
4551
4652def  read_file (path : str ) ->  torch .Tensor :
4753 """ 
48-  Reads and outputs the bytes contents of a file as a uint8 Tensor 
49-  with one dimension. 
54+  Return the bytes contents of a file as a uint8 1D Tensor. 
5055
5156 Args: 
5257 path (str or ``pathlib.Path``): the path to the file to be read 
@@ -62,8 +67,7 @@ def read_file(path: str) -> torch.Tensor:
6267
6368def  write_file (filename : str , data : torch .Tensor ) ->  None :
6469 """ 
65-  Writes the contents of an uint8 tensor with one dimension to a 
66-  file. 
70+  Write the content of an uint8 1D tensor to a file. 
6771
6872 Args: 
6973 filename (str or ``pathlib.Path``): the path to the file to be written 
@@ -93,10 +97,9 @@ def decode_png(
9397 Args: 
9498 input (Tensor[1]): a one dimensional uint8 tensor containing 
9599 the raw bytes of the PNG image. 
96-  mode (str or ImageReadMode): the read mode used for optionally 
97-  converting the image. Default: ``ImageReadMode.UNCHANGED``. 
98-  See `ImageReadMode` class for more information on various 
99-  available modes. 
100+  mode (str or ImageReadMode): The mode to convert the image to, e.g. "RGB". 
101+  Default is "UNCHANGED". See :class:`~torchvision.io.ImageReadMode` 
102+  for available modes. 
100103 apply_exif_orientation (bool): apply EXIF orientation transformation to the output tensor. 
101104 Default: False. 
102105
@@ -156,8 +159,7 @@ def decode_jpeg(
156159 device : Union [str , torch .device ] =  "cpu" ,
157160 apply_exif_orientation : bool  =  False ,
158161) ->  Union [torch .Tensor , List [torch .Tensor ]]:
159-  """ 
160-  Decode JPEG image(s) into 3 dimensional RGB or grayscale Tensor(s). 
162+  """Decode JPEG image(s) into 3D RGB or grayscale Tensor(s), on CPU or CUDA. 
161163
162164 The values of the output tensor are uint8 between 0 and 255. 
163165
@@ -171,12 +173,9 @@ def decode_jpeg(
171173 input (Tensor[1] or list[Tensor[1]]): a (list of) one dimensional uint8 tensor(s) containing 
172174 the raw bytes of the JPEG image. The tensor(s) must be on CPU, 
173175 regardless of the ``device`` parameter. 
174-  mode (str or ImageReadMode): the read mode used for optionally 
175-  converting the image(s). The supported modes are: ``ImageReadMode.UNCHANGED``, 
176-  ``ImageReadMode.GRAY`` and ``ImageReadMode.RGB`` 
177-  Default: ``ImageReadMode.UNCHANGED``. 
178-  See ``ImageReadMode`` class for more information on various 
179-  available modes. 
176+  mode (str or ImageReadMode): The mode to convert the image to, e.g. "RGB". 
177+  Default is "UNCHANGED". See :class:`~torchvision.io.ImageReadMode` 
178+  for available modes. 
180179 device (str or torch.device): The device on which the decoded image will 
181180 be stored. If a cuda device is specified, the image will be decoded 
182181 with `nvjpeg <https://developer.nvidia.com/nvjpeg>`_. This is only 
@@ -228,9 +227,7 @@ def decode_jpeg(
228227def  encode_jpeg (
229228 input : Union [torch .Tensor , List [torch .Tensor ]], quality : int  =  75 
230229) ->  Union [torch .Tensor , List [torch .Tensor ]]:
231-  """ 
232-  Takes a (list of) input tensor(s) in CHW layout and returns a (list of) buffer(s) with the contents 
233-  of the corresponding JPEG file(s). 
230+  """Encode RGB tensor(s) into raw encoded jpeg bytes, on CPU or CUDA. 
234231
235232 .. note:: 
236233 Passing a list of CUDA tensors is more efficient than repeated individual calls to ``encode_jpeg``. 
@@ -286,7 +283,7 @@ def decode_image(
286283 mode : ImageReadMode  =  ImageReadMode .UNCHANGED ,
287284 apply_exif_orientation : bool  =  False ,
288285) ->  torch .Tensor :
289-  """Decode an image into a tensor. 
286+  """Decode an image into a uint8  tensor, from a path or from raw encoded bytes . 
290287
291288 Currently supported image formats are jpeg, png, gif and webp. 
292289
@@ -303,10 +300,9 @@ def decode_image(
303300 input (Tensor or str or ``pathlib.Path``): The image to decode. If a 
304301 tensor is passed, it must be one dimensional uint8 tensor containing 
305302 the raw bytes of the image. Otherwise, this must be a path to the image file. 
306-  mode (str or ImageReadMode): the read mode used for optionally converting the image. 
307-  Default: ``ImageReadMode.UNCHANGED``. 
308-  See ``ImageReadMode`` class for more information on various 
309-  available modes. Only applies to JPEG and PNG images. 
303+  mode (str or ImageReadMode): The mode to convert the image to, e.g. "RGB". 
304+  Default is "UNCHANGED". See :class:`~torchvision.io.ImageReadMode` 
305+  for available modes. 
310306 apply_exif_orientation (bool): apply EXIF orientation transformation to the output tensor. 
311307 Only applies to JPEG and PNG images. Default: False. 
312308
@@ -367,9 +363,9 @@ def decode_webp(
367363 Args: 
368364 input (Tensor[1]): a one dimensional contiguous uint8 tensor containing 
369365 the raw bytes of the WEBP image. 
370-  mode (str or ImageReadMode): The read  mode used for optionally  
371-  converting the image color space. Default: ``ImageReadMode.UNCHANGED``.  
372-  Other supported values are ``ImageReadMode.RGB`` and ``ImageReadMode.RGB_ALPHA`` . 
366+  mode (str or ImageReadMode): The mode to convert the image to, e.g. "RGB".  
367+  Default is "UNCHANGED". See :class:`~torchvision.io.ImageReadMode`  
368+  for available modes . 
373369
374370 Returns: 
375371 Decoded image (Tensor[image_channels, image_height, image_width]) 
@@ -398,9 +394,9 @@ def _decode_avif(
398394 Args: 
399395 input (Tensor[1]): a one dimensional contiguous uint8 tensor containing 
400396 the raw bytes of the AVIF image. 
401-  mode (str or ImageReadMode): The read  mode used for optionally  
402-  converting the image color space. Default: ``ImageReadMode.UNCHANGED``.  
403-  Other supported values are ``ImageReadMode.RGB`` and ``ImageReadMode.RGB_ALPHA`` . 
397+  mode (str or ImageReadMode): The mode to convert the image to, e.g. "RGB".  
398+  Default is "UNCHANGED". See :class:`~torchvision.io.ImageReadMode`  
399+  for available modes . 
404400
405401 Returns: 
406402 Decoded image (Tensor[image_channels, image_height, image_width]) 
@@ -426,9 +422,9 @@ def _decode_heic(input: torch.Tensor, mode: ImageReadMode = ImageReadMode.UNCHAN
426422 Args: 
427423 input (Tensor[1]): a one dimensional contiguous uint8 tensor containing 
428424 the raw bytes of the HEIC image. 
429-  mode (str or ImageReadMode): The read  mode used for optionally  
430-  converting the image color space. Default: ``ImageReadMode.UNCHANGED``.  
431-  Other supported values are ``ImageReadMode.RGB`` and ``ImageReadMode.RGB_ALPHA`` . 
425+  mode (str or ImageReadMode): The mode to convert the image to, e.g. "RGB".  
426+  Default is "UNCHANGED". See :class:`~torchvision.io.ImageReadMode`  
427+  for available modes . 
432428
433429 Returns: 
434430 Decoded image (Tensor[image_channels, image_height, image_width]) 
0 commit comments