Repository: pytorch/vision

Issue:
Possible bug in function `decode_jpeg` in module `torchvision/io/image.py`
### 🐛 Describe the bug

The second argument to the function [decode_jpeg](https://github.com/pytorch/vision/blob/main/torchvision/io/image.py#L127) in the package torchvision.io is of the type [ImageReadMode](https://github.com/pytorch/vision/blob/dbbc5c8e93fbd3b301c7f76d3798d3041ca4bdaa/torchvision/io/image.py#L16), which is an enum.

However, passing `ImageReadMode.GRAY_ALPHA` or `ImageReadMode.RGB_ALPHA` as the second argument to [decode_jpeg](https://github.com/pytorch/vision/blob/main/torchvision/io/image.py#L127)  results in a crash (shown below).
I am not sure if it is a bug, but the docstring of [decode_jpeg](https://github.com/pytorch/vision/blob/main/torchvision/io/image.py#L127) does not mention this limitation.

## Failing test to reproduce the crash

Running the following test in the directory [test](https://github.com/pytorch/vision/tree/main/test) reproduces the crash.

```
from torchvision.io.image import ImageReadMode, read_file, decode_jpeg

def test_decode_jpeg_mode_alpha():
    path_jpg = 'assets/encode_jpeg/grace_hopper_517x606.jpg'
    content_tensor = read_file(path_jpg)
    decode_jpeg(content_tensor, ImageReadMode.GRAY_ALPHA)
    decode_jpeg(content_tensor, ImageReadMode.RGB_ALPHA)

```

## Error message

```
test_image_manual_user1.py::test_decode_jpeg_mode_alpha FAILED             [100%]
test/test_image_manual_user1.py:3 (test_decode_jpeg_mode_alpha)
Traceback (most recent call last):
  File "/home/user1/vision/test/test_image_manual_user1.py", line 7, in test_decode_jpeg_mode_alpha
    decode_jpeg(content_tensor, ImageReadMode.GRAY_ALPHA)
  File "/home/user1/vision/torchvision/io/image.py", line 220, in decode_jpeg
    output = torch.ops.image.decode_jpeg(input, mode.value)
  File "/home/user1/anaconda3/envs/vision_cov7/lib/python3.8/site-packages/torch/_ops.py", line 175, in __call__
    return self._op(*args, **kwargs or {})
RuntimeError: The provided mode is not supported for JPEG files
```


### Versions

Collecting environment information...
PyTorch version: 1.13.0.dev20220914
Is debug build: False
CUDA used to build PyTorch: 11.3
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.5 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.31

Python version: 3.8.13 (default, Mar 28 2022, 11:38:47)  [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.15.0-46-generic-x86_64-with-glibc2.17
Is CUDA available: False
CUDA runtime version: No CUDA
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

Versions of relevant libraries:
[pip3] mypy==0.971
[pip3] mypy-extensions==0.4.3
[pip3] numpy==1.22.4
[pip3] torch==1.13.0.dev20220914
[pip3] torchvision==0.14.0a0+b4686f2
[conda] blas                      1.0                         mkl  
[conda] cudatoolkit               11.3.1               h2bc3f7f_2  
[conda] mkl                       2022.1.0           hc2b9512_224  
[conda] numpy                     1.22.4                   pypi_0    pypi
[conda] pytorch                   1.13.0.dev20220914 py3.8_cuda11.3_cudnn8.3.2_0    pytorch-nightly
[conda] pytorch-mutex             1.0                        cuda    pytorch-nightly
[conda] torchvision               0.14.0a0+b4686f2           dev_0    <develop>



Discussion:
Thanks for the report @mohrez86 . That's not a bug - we don't support transparancy for jpeg encoding/decoding (TIL it can theorically be supported, but I'm not sure this is quite common in general). You might want to switch to PNGs for that.

I agree the doc could be a little clearer on the possible values though - would you like to open a PR for this?

Resolving patch:
diff --git a/torchvision/io/image.py b/torchvision/io/image.py
--- a/torchvision/io/image.py
+++ b/torchvision/io/image.py
@@ -137,7 +137,9 @@ def decode_jpeg(
             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``.
+            converting the image. The supported modes are: ``ImageReadMode.UNCHANGED``,
+            ``ImageReadMode.GRAY`` and ``ImageReadMode.RGB``
+            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


Test patch: