We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
`Tensor.to` does not work with feature as reference
`torch.Tensor.to` accepts a tensor reference object as input in which case it converts to the reference dtype and device:

```py
>>> a = torch.zeros((), dtype=torch.float)
>>> b = torch.ones((), dtype=torch.int)
>>> b
tensor(1, dtype=torch.int32)
>>> b.to(a)
tensor(1.)
```

This also works for our custom features:

```py
>>> data = torch.rand(3, 2, 2)
>>> image = features.Image(data.to(torch.float64))
>>> image
Image([[[0.9595, 0.0947],
        [0.9553, 0.5563]],
       [[0.5435, 0.2975],
        [0.3037, 0.0863]],
       [[0.6253, 0.3481],
        [0.3518, 0.4499]]], dtype=torch.float64)
>>> image.to(torch.float32)
Image([[[0.9595, 0.0947],
        [0.9553, 0.5563]],
       [[0.5435, 0.2975],
        [0.3037, 0.0863]],
       [[0.6253, 0.3481],
        [0.3518, 0.4499]]])
>>> image.to(data)
Image([[[0.9595, 0.0947],
        [0.9553, 0.5563]],
       [[0.5435, 0.2975],
        [0.3037, 0.0863]],
       [[0.6253, 0.3481],
        [0.3518, 0.4499]]])

```

However, it doesn't work if we want to convert a plain tensor and use a custom feature as reference:

```py
>>> data.to(image)
AttributeError: 'Tensor' object has no attribute 'color_space'
```

cc @bjuncek @pmeier

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `torchvision/prototype/features/_feature.py`
Content:
```
1 from __future__ import annotations
2 
3 from types import ModuleType
4 from typing import Any, Callable, cast, List, Mapping, Optional, Sequence, Tuple, Type, TypeVar, Union
5 
6 import PIL.Image
7 import torch
8 from torch._C import _TensorBase, DisableTorchFunction
9 from torchvision.transforms import InterpolationMode
10 
11 F = TypeVar("F", bound="_Feature")
12 FillType = Union[int, float, Sequence[int], Sequence[float], None]
13 FillTypeJIT = Union[int, float, List[float], None]
14 
15 
16 def is_simple_tensor(inpt: Any) -> bool:
17     return isinstance(inpt, torch.Tensor) and not isinstance(inpt, _Feature)
18 
19 
20 class _Feature(torch.Tensor):
21     __F: Optional[ModuleType] = None
22 
23     def __new__(
24         cls: Type[F],
25         data: Any,
26         *,
27         dtype: Optional[torch.dtype] = None,
28         device: Optional[Union[torch.device, str, int]] = None,
29         requires_grad: bool = False,
30     ) -> F:
31         return cast(
32             F,
33             torch.Tensor._make_subclass(
34                 cast(_TensorBase, cls),
35                 torch.as_tensor(data, dtype=dtype, device=device),  # type: ignore[arg-type]
36                 requires_grad,
37             ),
38         )
39 
40     @classmethod
41     def new_like(
42         cls: Type[F],
43         other: F,
44         data: Any,
45         *,
46         dtype: Optional[torch.dtype] = None,
47         device: Optional[Union[torch.device, str, int]] = None,
48         requires_grad: Optional[bool] = None,
49         **kwargs: Any,
50     ) -> F:
51         return cls(
52             data,
53             dtype=dtype if dtype is not None else other.dtype,
54             device=device if device is not None else other.device,
55             requires_grad=requires_grad if requires_grad is not None else other.requires_grad,
56             **kwargs,
57         )
58 
59     @classmethod
60     def __torch_function__(
61         cls,
62         func: Callable[..., torch.Tensor],
63         types: Tuple[Type[torch.Tensor], ...],
64         args: Sequence[Any] = (),
65         kwargs: Optional[Mapping[str, Any]] = None,
66     ) -> torch.Tensor:
67         """For general information about how the __torch_function__ protocol works,
68         see https://pytorch.org/docs/stable/notes/extending.html#extending-torch
69 
70         TL;DR: Every time a PyTorch operator is called, it goes through the inputs and looks for the
71         ``__torch_function__`` method. If one is found, it is invoked with the operator as ``func`` as well as the
72         ``args`` and ``kwargs`` of the original call.
73 
74         The default behavior of :class:`~torch.Tensor`'s is to retain a custom tensor type. For the :class:`Feature`
75         use case, this has two downsides:
76 
77         1. Since some :class:`Feature`'s require metadata to be constructed, the default wrapping, i.e.
78            ``return cls(func(*args, **kwargs))``, will fail for them.
79         2. For most operations, there is no way of knowing if the input type is still valid for the output.
80 
81         For these reasons, the automatic output wrapping is turned off for most operators.
82 
83         Exceptions to this are:
84 
85         - :func:`torch.clone`
86         - :meth:`torch.Tensor.to`
87         """
88         kwargs = kwargs or dict()
89         with DisableTorchFunction():
90             output = func(*args, **kwargs)
91 
92         if func is torch.Tensor.clone:
93             return cls.new_like(args[0], output)
94         elif func is torch.Tensor.to:
95             return cls.new_like(args[0], output, dtype=output.dtype, device=output.device)
96         else:
97             return output
98 
99     def _make_repr(self, **kwargs: Any) -> str:
100         # This is a poor man's implementation of the proposal in https://github.com/pytorch/pytorch/issues/76532.
101         # If that ever gets implemented, remove this in favor of the solution on the `torch.Tensor` class.
102         extra_repr = ", ".join(f"{key}={value}" for key, value in kwargs.items())
103         return f"{super().__repr__()[:-1]}, {extra_repr})"
104 
105     @property
106     def _F(self) -> ModuleType:
107         # This implements a lazy import of the functional to get around the cyclic import. This import is deferred
108         # until the first time we need reference to the functional module and it's shared across all instances of
109         # the class. This approach avoids the DataLoader issue described at
110         # https://github.com/pytorch/vision/pull/6476#discussion_r953588621
111         if _Feature.__F is None:
112             from ..transforms import functional
113 
114             _Feature.__F = functional
115         return _Feature.__F
116 
117     def horizontal_flip(self) -> _Feature:
118         return self
119 
120     def vertical_flip(self) -> _Feature:
121         return self
122 
123     # TODO: We have to ignore override mypy error as there is torch.Tensor built-in deprecated op: Tensor.resize
124     # https://github.com/pytorch/pytorch/blob/e8727994eb7cdb2ab642749d6549bc497563aa06/torch/_tensor.py#L588-L593
125     def resize(  # type: ignore[override]
126         self,
127         size: List[int],
128         interpolation: InterpolationMode = InterpolationMode.BILINEAR,
129         max_size: Optional[int] = None,
130         antialias: bool = False,
131     ) -> _Feature:
132         return self
133 
134     def crop(self, top: int, left: int, height: int, width: int) -> _Feature:
135         return self
136 
137     def center_crop(self, output_size: List[int]) -> _Feature:
138         return self
139 
140     def resized_crop(
141         self,
142         top: int,
143         left: int,
144         height: int,
145         width: int,
146         size: List[int],
147         interpolation: InterpolationMode = InterpolationMode.BILINEAR,
148         antialias: bool = False,
149     ) -> _Feature:
150         return self
151 
152     def pad(
153         self,
154         padding: Union[int, List[int]],
155         fill: FillTypeJIT = None,
156         padding_mode: str = "constant",
157     ) -> _Feature:
158         return self
159 
160     def rotate(
161         self,
162         angle: float,
163         interpolation: InterpolationMode = InterpolationMode.NEAREST,
164         expand: bool = False,
165         fill: FillTypeJIT = None,
166         center: Optional[List[float]] = None,
167     ) -> _Feature:
168         return self
169 
170     def affine(
171         self,
172         angle: Union[int, float],
173         translate: List[float],
174         scale: float,
175         shear: List[float],
176         interpolation: InterpolationMode = InterpolationMode.NEAREST,
177         fill: FillTypeJIT = None,
178         center: Optional[List[float]] = None,
179     ) -> _Feature:
180         return self
181 
182     def perspective(
183         self,
184         perspective_coeffs: List[float],
185         interpolation: InterpolationMode = InterpolationMode.BILINEAR,
186         fill: FillTypeJIT = None,
187     ) -> _Feature:
188         return self
189 
190     def elastic(
191         self,
192         displacement: torch.Tensor,
193         interpolation: InterpolationMode = InterpolationMode.BILINEAR,
194         fill: FillTypeJIT = None,
195     ) -> _Feature:
196         return self
197 
198     def adjust_brightness(self, brightness_factor: float) -> _Feature:
199         return self
200 
201     def adjust_saturation(self, saturation_factor: float) -> _Feature:
202         return self
203 
204     def adjust_contrast(self, contrast_factor: float) -> _Feature:
205         return self
206 
207     def adjust_sharpness(self, sharpness_factor: float) -> _Feature:
208         return self
209 
210     def adjust_hue(self, hue_factor: float) -> _Feature:
211         return self
212 
213     def adjust_gamma(self, gamma: float, gain: float = 1) -> _Feature:
214         return self
215 
216     def posterize(self, bits: int) -> _Feature:
217         return self
218 
219     def solarize(self, threshold: float) -> _Feature:
220         return self
221 
222     def autocontrast(self) -> _Feature:
223         return self
224 
225     def equalize(self) -> _Feature:
226         return self
227 
228     def invert(self) -> _Feature:
229         return self
230 
231     def gaussian_blur(self, kernel_size: List[int], sigma: Optional[List[float]] = None) -> _Feature:
232         return self
233 
234 
235 InputType = Union[torch.Tensor, PIL.Image.Image, _Feature]
236 InputTypeJIT = torch.Tensor
237
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/torchvision/prototype/features/_feature.py b/torchvision/prototype/features/_feature.py
--- a/torchvision/prototype/features/_feature.py
+++ b/torchvision/prototype/features/_feature.py
@@ -89,6 +89,13 @@
         with DisableTorchFunction():
             output = func(*args, **kwargs)
 
+        # The __torch_function__ protocol will invoke this method on all types involved in the computation by walking
+        # the MRO upwards. For example, `torch.Tensor(...).to(features.Image(...))` will invoke
+        # `features.Image.__torch_function__` first. The check below makes sure that we do not try to wrap in such a
+        # case.
+        if not isinstance(args[0], cls):
+            return output
+
         if func is torch.Tensor.clone:
             return cls.new_like(args[0], output)
         elif func is torch.Tensor.to:

{"golden_diff": "diff --git a/torchvision/prototype/features/_feature.py b/torchvision/prototype/features/_feature.py\n--- a/torchvision/prototype/features/_feature.py\n+++ b/torchvision/prototype/features/_feature.py\n@@ -89,6 +89,13 @@\n         with DisableTorchFunction():\n             output = func(*args, **kwargs)\n \n+        # The __torch_function__ protocol will invoke this method on all types involved in the computation by walking\n+        # the MRO upwards. For example, `torch.Tensor(...).to(features.Image(...))` will invoke\n+        # `features.Image.__torch_function__` first. The check below makes sure that we do not try to wrap in such a\n+        # case.\n+        if not isinstance(args[0], cls):\n+            return output\n+\n         if func is torch.Tensor.clone:\n             return cls.new_like(args[0], output)\n         elif func is torch.Tensor.to:\n", "issue": "`Tensor.to` does not work with feature as reference\n`torch.Tensor.to` accepts a tensor reference object as input in which case it converts to the reference dtype and device:\r\n\r\n```py\r\n>>> a = torch.zeros((), dtype=torch.float)\r\n>>> b = torch.ones((), dtype=torch.int)\r\n>>> b\r\ntensor(1, dtype=torch.int32)\r\n>>> b.to(a)\r\ntensor(1.)\r\n```\r\n\r\nThis also works for our custom features:\r\n\r\n```py\r\n>>> data = torch.rand(3, 2, 2)\r\n>>> image = features.Image(data.to(torch.float64))\r\n>>> image\r\nImage([[[0.9595, 0.0947],\r\n        [0.9553, 0.5563]],\r\n       [[0.5435, 0.2975],\r\n        [0.3037, 0.0863]],\r\n       [[0.6253, 0.3481],\r\n        [0.3518, 0.4499]]], dtype=torch.float64)\r\n>>> image.to(torch.float32)\r\nImage([[[0.9595, 0.0947],\r\n        [0.9553, 0.5563]],\r\n       [[0.5435, 0.2975],\r\n        [0.3037, 0.0863]],\r\n       [[0.6253, 0.3481],\r\n        [0.3518, 0.4499]]])\r\n>>> image.to(data)\r\nImage([[[0.9595, 0.0947],\r\n        [0.9553, 0.5563]],\r\n       [[0.5435, 0.2975],\r\n        [0.3037, 0.0863]],\r\n       [[0.6253, 0.3481],\r\n        [0.3518, 0.4499]]])\r\n\r\n```\r\n\r\nHowever, it doesn't work if we want to convert a plain tensor and use a custom feature as reference:\r\n\r\n```py\r\n>>> data.to(image)\r\nAttributeError: 'Tensor' object has no attribute 'color_space'\r\n```\n\ncc @bjuncek @pmeier\n", "before_files": [{"content": "from __future__ import annotations\n\nfrom types import ModuleType\nfrom typing import Any, Callable, cast, List, Mapping, Optional, Sequence, Tuple, Type, TypeVar, Union\n\nimport PIL.Image\nimport torch\nfrom torch._C import _TensorBase, DisableTorchFunction\nfrom torchvision.transforms import InterpolationMode\n\nF = TypeVar(\"F\", bound=\"_Feature\")\nFillType = Union[int, float, Sequence[int], Sequence[float], None]\nFillTypeJIT = Union[int, float, List[float], None]\n\n\ndef is_simple_tensor(inpt: Any) -> bool:\n    return isinstance(inpt, torch.Tensor) and not isinstance(inpt, _Feature)\n\n\nclass _Feature(torch.Tensor):\n    __F: Optional[ModuleType] = None\n\n    def __new__(\n        cls: Type[F],\n        data: Any,\n        *,\n        dtype: Optional[torch.dtype] = None,\n        device: Optional[Union[torch.device, str, int]] = None,\n        requires_grad: bool = False,\n    ) -> F:\n        return cast(\n            F,\n            torch.Tensor._make_subclass(\n                cast(_TensorBase, cls),\n                torch.as_tensor(data, dtype=dtype, device=device),  # type: ignore[arg-type]\n                requires_grad,\n            ),\n        )\n\n    @classmethod\n    def new_like(\n        cls: Type[F],\n        other: F,\n        data: Any,\n        *,\n        dtype: Optional[torch.dtype] = None,\n        device: Optional[Union[torch.device, str, int]] = None,\n        requires_grad: Optional[bool] = None,\n        **kwargs: Any,\n    ) -> F:\n        return cls(\n            data,\n            dtype=dtype if dtype is not None else other.dtype,\n            device=device if device is not None else other.device,\n            requires_grad=requires_grad if requires_grad is not None else other.requires_grad,\n            **kwargs,\n        )\n\n    @classmethod\n    def __torch_function__(\n        cls,\n        func: Callable[..., torch.Tensor],\n        types: Tuple[Type[torch.Tensor], ...],\n        args: Sequence[Any] = (),\n        kwargs: Optional[Mapping[str, Any]] = None,\n    ) -> torch.Tensor:\n        \"\"\"For general information about how the __torch_function__ protocol works,\n        see https://pytorch.org/docs/stable/notes/extending.html#extending-torch\n\n        TL;DR: Every time a PyTorch operator is called, it goes through the inputs and looks for the\n        ``__torch_function__`` method. If one is found, it is invoked with the operator as ``func`` as well as the\n        ``args`` and ``kwargs`` of the original call.\n\n        The default behavior of :class:`~torch.Tensor`'s is to retain a custom tensor type. For the :class:`Feature`\n        use case, this has two downsides:\n\n        1. Since some :class:`Feature`'s require metadata to be constructed, the default wrapping, i.e.\n           ``return cls(func(*args, **kwargs))``, will fail for them.\n        2. For most operations, there is no way of knowing if the input type is still valid for the output.\n\n        For these reasons, the automatic output wrapping is turned off for most operators.\n\n        Exceptions to this are:\n\n        - :func:`torch.clone`\n        - :meth:`torch.Tensor.to`\n        \"\"\"\n        kwargs = kwargs or dict()\n        with DisableTorchFunction():\n            output = func(*args, **kwargs)\n\n        if func is torch.Tensor.clone:\n            return cls.new_like(args[0], output)\n        elif func is torch.Tensor.to:\n            return cls.new_like(args[0], output, dtype=output.dtype, device=output.device)\n        else:\n            return output\n\n    def _make_repr(self, **kwargs: Any) -> str:\n        # This is a poor man's implementation of the proposal in https://github.com/pytorch/pytorch/issues/76532.\n        # If that ever gets implemented, remove this in favor of the solution on the `torch.Tensor` class.\n        extra_repr = \", \".join(f\"{key}={value}\" for key, value in kwargs.items())\n        return f\"{super().__repr__()[:-1]}, {extra_repr})\"\n\n    @property\n    def _F(self) -> ModuleType:\n        # This implements a lazy import of the functional to get around the cyclic import. This import is deferred\n        # until the first time we need reference to the functional module and it's shared across all instances of\n        # the class. This approach avoids the DataLoader issue described at\n        # https://github.com/pytorch/vision/pull/6476#discussion_r953588621\n        if _Feature.__F is None:\n            from ..transforms import functional\n\n            _Feature.__F = functional\n        return _Feature.__F\n\n    def horizontal_flip(self) -> _Feature:\n        return self\n\n    def vertical_flip(self) -> _Feature:\n        return self\n\n    # TODO: We have to ignore override mypy error as there is torch.Tensor built-in deprecated op: Tensor.resize\n    # https://github.com/pytorch/pytorch/blob/e8727994eb7cdb2ab642749d6549bc497563aa06/torch/_tensor.py#L588-L593\n    def resize(  # type: ignore[override]\n        self,\n        size: List[int],\n        interpolation: InterpolationMode = InterpolationMode.BILINEAR,\n        max_size: Optional[int] = None,\n        antialias: bool = False,\n    ) -> _Feature:\n        return self\n\n    def crop(self, top: int, left: int, height: int, width: int) -> _Feature:\n        return self\n\n    def center_crop(self, output_size: List[int]) -> _Feature:\n        return self\n\n    def resized_crop(\n        self,\n        top: int,\n        left: int,\n        height: int,\n        width: int,\n        size: List[int],\n        interpolation: InterpolationMode = InterpolationMode.BILINEAR,\n        antialias: bool = False,\n    ) -> _Feature:\n        return self\n\n    def pad(\n        self,\n        padding: Union[int, List[int]],\n        fill: FillTypeJIT = None,\n        padding_mode: str = \"constant\",\n    ) -> _Feature:\n        return self\n\n    def rotate(\n        self,\n        angle: float,\n        interpolation: InterpolationMode = InterpolationMode.NEAREST,\n        expand: bool = False,\n        fill: FillTypeJIT = None,\n        center: Optional[List[float]] = None,\n    ) -> _Feature:\n        return self\n\n    def affine(\n        self,\n        angle: Union[int, float],\n        translate: List[float],\n        scale: float,\n        shear: List[float],\n        interpolation: InterpolationMode = InterpolationMode.NEAREST,\n        fill: FillTypeJIT = None,\n        center: Optional[List[float]] = None,\n    ) -> _Feature:\n        return self\n\n    def perspective(\n        self,\n        perspective_coeffs: List[float],\n        interpolation: InterpolationMode = InterpolationMode.BILINEAR,\n        fill: FillTypeJIT = None,\n    ) -> _Feature:\n        return self\n\n    def elastic(\n        self,\n        displacement: torch.Tensor,\n        interpolation: InterpolationMode = InterpolationMode.BILINEAR,\n        fill: FillTypeJIT = None,\n    ) -> _Feature:\n        return self\n\n    def adjust_brightness(self, brightness_factor: float) -> _Feature:\n        return self\n\n    def adjust_saturation(self, saturation_factor: float) -> _Feature:\n        return self\n\n    def adjust_contrast(self, contrast_factor: float) -> _Feature:\n        return self\n\n    def adjust_sharpness(self, sharpness_factor: float) -> _Feature:\n        return self\n\n    def adjust_hue(self, hue_factor: float) -> _Feature:\n        return self\n\n    def adjust_gamma(self, gamma: float, gain: float = 1) -> _Feature:\n        return self\n\n    def posterize(self, bits: int) -> _Feature:\n        return self\n\n    def solarize(self, threshold: float) -> _Feature:\n        return self\n\n    def autocontrast(self) -> _Feature:\n        return self\n\n    def equalize(self) -> _Feature:\n        return self\n\n    def invert(self) -> _Feature:\n        return self\n\n    def gaussian_blur(self, kernel_size: List[int], sigma: Optional[List[float]] = None) -> _Feature:\n        return self\n\n\nInputType = Union[torch.Tensor, PIL.Image.Image, _Feature]\nInputTypeJIT = torch.Tensor\n", "path": "torchvision/prototype/features/_feature.py"}], "after_files": [{"content": "from __future__ import annotations\n\nfrom types import ModuleType\nfrom typing import Any, Callable, cast, List, Mapping, Optional, Sequence, Tuple, Type, TypeVar, Union\n\nimport PIL.Image\nimport torch\nfrom torch._C import _TensorBase, DisableTorchFunction\nfrom torchvision.transforms import InterpolationMode\n\nF = TypeVar(\"F\", bound=\"_Feature\")\nFillType = Union[int, float, Sequence[int], Sequence[float], None]\nFillTypeJIT = Union[int, float, List[float], None]\n\n\ndef is_simple_tensor(inpt: Any) -> bool:\n    return isinstance(inpt, torch.Tensor) and not isinstance(inpt, _Feature)\n\n\nclass _Feature(torch.Tensor):\n    __F: Optional[ModuleType] = None\n\n    def __new__(\n        cls: Type[F],\n        data: Any,\n        *,\n        dtype: Optional[torch.dtype] = None,\n        device: Optional[Union[torch.device, str, int]] = None,\n        requires_grad: bool = False,\n    ) -> F:\n        return cast(\n            F,\n            torch.Tensor._make_subclass(\n                cast(_TensorBase, cls),\n                torch.as_tensor(data, dtype=dtype, device=device),  # type: ignore[arg-type]\n                requires_grad,\n            ),\n        )\n\n    @classmethod\n    def new_like(\n        cls: Type[F],\n        other: F,\n        data: Any,\n        *,\n        dtype: Optional[torch.dtype] = None,\n        device: Optional[Union[torch.device, str, int]] = None,\n        requires_grad: Optional[bool] = None,\n        **kwargs: Any,\n    ) -> F:\n        return cls(\n            data,\n            dtype=dtype if dtype is not None else other.dtype,\n            device=device if device is not None else other.device,\n            requires_grad=requires_grad if requires_grad is not None else other.requires_grad,\n            **kwargs,\n        )\n\n    @classmethod\n    def __torch_function__(\n        cls,\n        func: Callable[..., torch.Tensor],\n        types: Tuple[Type[torch.Tensor], ...],\n        args: Sequence[Any] = (),\n        kwargs: Optional[Mapping[str, Any]] = None,\n    ) -> torch.Tensor:\n        \"\"\"For general information about how the __torch_function__ protocol works,\n        see https://pytorch.org/docs/stable/notes/extending.html#extending-torch\n\n        TL;DR: Every time a PyTorch operator is called, it goes through the inputs and looks for the\n        ``__torch_function__`` method. If one is found, it is invoked with the operator as ``func`` as well as the\n        ``args`` and ``kwargs`` of the original call.\n\n        The default behavior of :class:`~torch.Tensor`'s is to retain a custom tensor type. For the :class:`Feature`\n        use case, this has two downsides:\n\n        1. Since some :class:`Feature`'s require metadata to be constructed, the default wrapping, i.e.\n           ``return cls(func(*args, **kwargs))``, will fail for them.\n        2. For most operations, there is no way of knowing if the input type is still valid for the output.\n\n        For these reasons, the automatic output wrapping is turned off for most operators.\n\n        Exceptions to this are:\n\n        - :func:`torch.clone`\n        - :meth:`torch.Tensor.to`\n        \"\"\"\n        kwargs = kwargs or dict()\n        with DisableTorchFunction():\n            output = func(*args, **kwargs)\n\n        # The __torch_function__ protocol will invoke this method on all types involved in the computation by walking\n        # the MRO upwards. For example, `torch.Tensor(...).to(features.Image(...))` will invoke\n        # `features.Image.__torch_function__` first. The check below makes sure that we do not try to wrap in such a\n        # case.\n        if not isinstance(args[0], cls):\n            return output\n\n        if func is torch.Tensor.clone:\n            return cls.new_like(args[0], output)\n        elif func is torch.Tensor.to:\n            return cls.new_like(args[0], output, dtype=output.dtype, device=output.device)\n        else:\n            return output\n\n    def _make_repr(self, **kwargs: Any) -> str:\n        # This is a poor man's implementation of the proposal in https://github.com/pytorch/pytorch/issues/76532.\n        # If that ever gets implemented, remove this in favor of the solution on the `torch.Tensor` class.\n        extra_repr = \", \".join(f\"{key}={value}\" for key, value in kwargs.items())\n        return f\"{super().__repr__()[:-1]}, {extra_repr})\"\n\n    @property\n    def _F(self) -> ModuleType:\n        # This implements a lazy import of the functional to get around the cyclic import. This import is deferred\n        # until the first time we need reference to the functional module and it's shared across all instances of\n        # the class. This approach avoids the DataLoader issue described at\n        # https://github.com/pytorch/vision/pull/6476#discussion_r953588621\n        if _Feature.__F is None:\n            from ..transforms import functional\n\n            _Feature.__F = functional\n        return _Feature.__F\n\n    def horizontal_flip(self) -> _Feature:\n        return self\n\n    def vertical_flip(self) -> _Feature:\n        return self\n\n    # TODO: We have to ignore override mypy error as there is torch.Tensor built-in deprecated op: Tensor.resize\n    # https://github.com/pytorch/pytorch/blob/e8727994eb7cdb2ab642749d6549bc497563aa06/torch/_tensor.py#L588-L593\n    def resize(  # type: ignore[override]\n        self,\n        size: List[int],\n        interpolation: InterpolationMode = InterpolationMode.BILINEAR,\n        max_size: Optional[int] = None,\n        antialias: bool = False,\n    ) -> _Feature:\n        return self\n\n    def crop(self, top: int, left: int, height: int, width: int) -> _Feature:\n        return self\n\n    def center_crop(self, output_size: List[int]) -> _Feature:\n        return self\n\n    def resized_crop(\n        self,\n        top: int,\n        left: int,\n        height: int,\n        width: int,\n        size: List[int],\n        interpolation: InterpolationMode = InterpolationMode.BILINEAR,\n        antialias: bool = False,\n    ) -> _Feature:\n        return self\n\n    def pad(\n        self,\n        padding: Union[int, List[int]],\n        fill: FillTypeJIT = None,\n        padding_mode: str = \"constant\",\n    ) -> _Feature:\n        return self\n\n    def rotate(\n        self,\n        angle: float,\n        interpolation: InterpolationMode = InterpolationMode.NEAREST,\n        expand: bool = False,\n        fill: FillTypeJIT = None,\n        center: Optional[List[float]] = None,\n    ) -> _Feature:\n        return self\n\n    def affine(\n        self,\n        angle: Union[int, float],\n        translate: List[float],\n        scale: float,\n        shear: List[float],\n        interpolation: InterpolationMode = InterpolationMode.NEAREST,\n        fill: FillTypeJIT = None,\n        center: Optional[List[float]] = None,\n    ) -> _Feature:\n        return self\n\n    def perspective(\n        self,\n        perspective_coeffs: List[float],\n        interpolation: InterpolationMode = InterpolationMode.BILINEAR,\n        fill: FillTypeJIT = None,\n    ) -> _Feature:\n        return self\n\n    def elastic(\n        self,\n        displacement: torch.Tensor,\n        interpolation: InterpolationMode = InterpolationMode.BILINEAR,\n        fill: FillTypeJIT = None,\n    ) -> _Feature:\n        return self\n\n    def adjust_brightness(self, brightness_factor: float) -> _Feature:\n        return self\n\n    def adjust_saturation(self, saturation_factor: float) -> _Feature:\n        return self\n\n    def adjust_contrast(self, contrast_factor: float) -> _Feature:\n        return self\n\n    def adjust_sharpness(self, sharpness_factor: float) -> _Feature:\n        return self\n\n    def adjust_hue(self, hue_factor: float) -> _Feature:\n        return self\n\n    def adjust_gamma(self, gamma: float, gain: float = 1) -> _Feature:\n        return self\n\n    def posterize(self, bits: int) -> _Feature:\n        return self\n\n    def solarize(self, threshold: float) -> _Feature:\n        return self\n\n    def autocontrast(self) -> _Feature:\n        return self\n\n    def equalize(self) -> _Feature:\n        return self\n\n    def invert(self) -> _Feature:\n        return self\n\n    def gaussian_blur(self, kernel_size: List[int], sigma: Optional[List[float]] = None) -> _Feature:\n        return self\n\n\nInputType = Union[torch.Tensor, PIL.Image.Image, _Feature]\nInputTypeJIT = torch.Tensor\n", "path": "torchvision/prototype/features/_feature.py"}]}