_deprecated.py 1.46 KB
Newer Older
1
import warnings
2
from typing import Any, List, Union
3
4

import PIL.Image
5
import torch
6

7
from torchvision import datapoints
8
9
10
from torchvision.transforms import functional as _F


11
@torch.jit.unused
12
13
def to_grayscale(inpt: PIL.Image.Image, num_output_channels: int = 1) -> PIL.Image.Image:
    call = ", num_output_channels=3" if num_output_channels == 3 else ""
14
    replacement = "convert_color_space(..., color_space=datapoints.ColorSpace.GRAY)"
15
    if num_output_channels == 3:
16
        replacement = f"convert_color_space({replacement}, color_space=datapoints.ColorSpace.RGB)"
17
18
19
20
21
22
23
24
    warnings.warn(
        f"The function `to_grayscale(...{call})` is deprecated in will be removed in a future release. "
        f"Instead, please use `{replacement}`.",
    )

    return _F.to_grayscale(inpt, num_output_channels=num_output_channels)


25
@torch.jit.unused
26
27
28
29
30
31
def to_tensor(inpt: Any) -> torch.Tensor:
    warnings.warn(
        "The function `to_tensor(...)` is deprecated and will be removed in a future release. "
        "Instead, please use `to_image_tensor(...)` followed by `convert_image_dtype(...)`."
    )
    return _F.to_tensor(inpt)
32
33


Philip Meier's avatar
Philip Meier committed
34
def get_image_size(inpt: Union[datapoints._ImageTypeJIT, datapoints._VideoTypeJIT]) -> List[int]:
35
36
37
38
39
    warnings.warn(
        "The function `get_image_size(...)` is deprecated and will be removed in a future release. "
        "Instead, please use `get_spatial_size(...)` which returns `[h, w]` instead of `[w, h]`."
    )
    return _F.get_image_size(inpt)