We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Inconsistency between RoIPool's forward and roi_pool
### 🚀 The feature

Currently the functional `roi_pool` method supports both `Tensor` and `List[Tensor]` for boxes, but the module forward function of `RoIPool` expects boxes(rois) to be `Tensor` only. Can we change the function signature to support both? 

The inconsistency can cause issue during torchscripting, for example:
```
from typing import List
import torch
from torch import Tensor
from torchvision.ops import RoIPool

class Model(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.pool = RoIPool(output_size=[3,3], spatial_scale=1.0)

    def forward(self, imgs, boxes: List[Tensor]):
        return self.pool(imgs, boxes)

model = Model()
torch.jit.script(model)
```
Raise the following error:

> forward(__torch__.torchvision.ops.roi_pool.RoIPool self, Tensor input, Tensor rois) -> Tensor:
> Expected a value of type 'Tensor' for argument 'rois' but instead found type 'List[Tensor]'.
> Empty lists default to List[Tensor]. Add a variable annotation to the assignment to create an empty list of another type (torch.jit.annotate(List[T, []]) where T is the type of elements in the list for Python 2)
> :
>   File "<ipython-input-8-9536dd2f0cc1>", line 12
>     def forward(self, imgs, boxes: List[Tensor]):
>         return self.pool(imgs, boxes)
>                ~~~~~~~~~ <--- HERE

### Motivation, pitch

Make sure the model can be scriptable when using list of boxes as the input.

### Alternatives

Only support Tensor as the input, user are required to convert bbox of different images into one tensor. Potentially make `_utils.convert_boxes_to_roi_format` public so that users don't need to write the conversion function.

### Additional context

_No response_

--- 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/ops/roi_align.py`
Content:
```
1 from typing import List, Union
2 
3 import torch
4 from torch import nn, Tensor
5 from torch.jit.annotations import BroadcastingList2
6 from torch.nn.modules.utils import _pair
7 from torchvision.extension import _assert_has_ops
8 
9 from ..utils import _log_api_usage_once
10 from ._utils import check_roi_boxes_shape, convert_boxes_to_roi_format
11 
12 
13 def roi_align(
14     input: Tensor,
15     boxes: Union[Tensor, List[Tensor]],
16     output_size: BroadcastingList2[int],
17     spatial_scale: float = 1.0,
18     sampling_ratio: int = -1,
19     aligned: bool = False,
20 ) -> Tensor:
21     """
22     Performs Region of Interest (RoI) Align operator with average pooling, as described in Mask R-CNN.
23 
24     Args:
25         input (Tensor[N, C, H, W]): The input tensor, i.e. a batch with ``N`` elements. Each element
26             contains ``C`` feature maps of dimensions ``H x W``.
27             If the tensor is quantized, we expect a batch size of ``N == 1``.
28         boxes (Tensor[K, 5] or List[Tensor[L, 4]]): the box coordinates in (x1, y1, x2, y2)
29             format where the regions will be taken from.
30             The coordinate must satisfy ``0 <= x1 < x2`` and ``0 <= y1 < y2``.
31             If a single Tensor is passed, then the first column should
32             contain the index of the corresponding element in the batch, i.e. a number in ``[0, N - 1]``.
33             If a list of Tensors is passed, then each Tensor will correspond to the boxes for an element i
34             in the batch.
35         output_size (int or Tuple[int, int]): the size of the output (in bins or pixels) after the pooling
36             is performed, as (height, width).
37         spatial_scale (float): a scaling factor that maps the box coordinates to
38             the input coordinates. For example, if your boxes are defined on the scale
39             of a 224x224 image and your input is a 112x112 feature map (resulting from a 0.5x scaling of
40             the original image), you'll want to set this to 0.5. Default: 1.0
41         sampling_ratio (int): number of sampling points in the interpolation grid
42             used to compute the output value of each pooled output bin. If > 0,
43             then exactly ``sampling_ratio x sampling_ratio`` sampling points per bin are used. If
44             <= 0, then an adaptive number of grid points are used (computed as
45             ``ceil(roi_width / output_width)``, and likewise for height). Default: -1
46         aligned (bool): If False, use the legacy implementation.
47             If True, pixel shift the box coordinates it by -0.5 for a better alignment with the two
48             neighboring pixel indices. This version is used in Detectron2
49 
50     Returns:
51         Tensor[K, C, output_size[0], output_size[1]]: The pooled RoIs.
52     """
53     if not torch.jit.is_scripting() and not torch.jit.is_tracing():
54         _log_api_usage_once(roi_align)
55     _assert_has_ops()
56     check_roi_boxes_shape(boxes)
57     rois = boxes
58     output_size = _pair(output_size)
59     if not isinstance(rois, torch.Tensor):
60         rois = convert_boxes_to_roi_format(rois)
61     return torch.ops.torchvision.roi_align(
62         input, rois, spatial_scale, output_size[0], output_size[1], sampling_ratio, aligned
63     )
64 
65 
66 class RoIAlign(nn.Module):
67     """
68     See :func:`roi_align`.
69     """
70 
71     def __init__(
72         self,
73         output_size: BroadcastingList2[int],
74         spatial_scale: float,
75         sampling_ratio: int,
76         aligned: bool = False,
77     ):
78         super().__init__()
79         _log_api_usage_once(self)
80         self.output_size = output_size
81         self.spatial_scale = spatial_scale
82         self.sampling_ratio = sampling_ratio
83         self.aligned = aligned
84 
85     def forward(self, input: Tensor, rois: Tensor) -> Tensor:
86         return roi_align(input, rois, self.output_size, self.spatial_scale, self.sampling_ratio, self.aligned)
87 
88     def __repr__(self) -> str:
89         s = (
90             f"{self.__class__.__name__}("
91             f"output_size={self.output_size}"
92             f", spatial_scale={self.spatial_scale}"
93             f", sampling_ratio={self.sampling_ratio}"
94             f", aligned={self.aligned}"
95             f")"
96         )
97         return s
98
```

Path: `torchvision/ops/roi_pool.py`
Content:
```
1 from typing import List, Union
2 
3 import torch
4 from torch import nn, Tensor
5 from torch.jit.annotations import BroadcastingList2
6 from torch.nn.modules.utils import _pair
7 from torchvision.extension import _assert_has_ops
8 
9 from ..utils import _log_api_usage_once
10 from ._utils import check_roi_boxes_shape, convert_boxes_to_roi_format
11 
12 
13 def roi_pool(
14     input: Tensor,
15     boxes: Union[Tensor, List[Tensor]],
16     output_size: BroadcastingList2[int],
17     spatial_scale: float = 1.0,
18 ) -> Tensor:
19     """
20     Performs Region of Interest (RoI) Pool operator described in Fast R-CNN
21 
22     Args:
23         input (Tensor[N, C, H, W]): The input tensor, i.e. a batch with ``N`` elements. Each element
24             contains ``C`` feature maps of dimensions ``H x W``.
25         boxes (Tensor[K, 5] or List[Tensor[L, 4]]): the box coordinates in (x1, y1, x2, y2)
26             format where the regions will be taken from.
27             The coordinate must satisfy ``0 <= x1 < x2`` and ``0 <= y1 < y2``.
28             If a single Tensor is passed, then the first column should
29             contain the index of the corresponding element in the batch, i.e. a number in ``[0, N - 1]``.
30             If a list of Tensors is passed, then each Tensor will correspond to the boxes for an element i
31             in the batch.
32         output_size (int or Tuple[int, int]): the size of the output after the cropping
33             is performed, as (height, width)
34         spatial_scale (float): a scaling factor that maps the box coordinates to
35             the input coordinates. For example, if your boxes are defined on the scale
36             of a 224x224 image and your input is a 112x112 feature map (resulting from a 0.5x scaling of
37             the original image), you'll want to set this to 0.5. Default: 1.0
38 
39     Returns:
40         Tensor[K, C, output_size[0], output_size[1]]: The pooled RoIs.
41     """
42     if not torch.jit.is_scripting() and not torch.jit.is_tracing():
43         _log_api_usage_once(roi_pool)
44     _assert_has_ops()
45     check_roi_boxes_shape(boxes)
46     rois = boxes
47     output_size = _pair(output_size)
48     if not isinstance(rois, torch.Tensor):
49         rois = convert_boxes_to_roi_format(rois)
50     output, _ = torch.ops.torchvision.roi_pool(input, rois, spatial_scale, output_size[0], output_size[1])
51     return output
52 
53 
54 class RoIPool(nn.Module):
55     """
56     See :func:`roi_pool`.
57     """
58 
59     def __init__(self, output_size: BroadcastingList2[int], spatial_scale: float):
60         super().__init__()
61         _log_api_usage_once(self)
62         self.output_size = output_size
63         self.spatial_scale = spatial_scale
64 
65     def forward(self, input: Tensor, rois: Tensor) -> Tensor:
66         return roi_pool(input, rois, self.output_size, self.spatial_scale)
67 
68     def __repr__(self) -> str:
69         s = f"{self.__class__.__name__}(output_size={self.output_size}, spatial_scale={self.spatial_scale})"
70         return s
71
```
--- 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/ops/roi_align.py b/torchvision/ops/roi_align.py
--- a/torchvision/ops/roi_align.py
+++ b/torchvision/ops/roi_align.py
@@ -82,7 +82,7 @@
         self.sampling_ratio = sampling_ratio
         self.aligned = aligned
 
-    def forward(self, input: Tensor, rois: Tensor) -> Tensor:
+    def forward(self, input: Tensor, rois: Union[Tensor, List[Tensor]]) -> Tensor:
         return roi_align(input, rois, self.output_size, self.spatial_scale, self.sampling_ratio, self.aligned)
 
     def __repr__(self) -> str:
diff --git a/torchvision/ops/roi_pool.py b/torchvision/ops/roi_pool.py
--- a/torchvision/ops/roi_pool.py
+++ b/torchvision/ops/roi_pool.py
@@ -62,7 +62,7 @@
         self.output_size = output_size
         self.spatial_scale = spatial_scale
 
-    def forward(self, input: Tensor, rois: Tensor) -> Tensor:
+    def forward(self, input: Tensor, rois: Union[Tensor, List[Tensor]]) -> Tensor:
         return roi_pool(input, rois, self.output_size, self.spatial_scale)
 
     def __repr__(self) -> str:

{"golden_diff": "diff --git a/torchvision/ops/roi_align.py b/torchvision/ops/roi_align.py\n--- a/torchvision/ops/roi_align.py\n+++ b/torchvision/ops/roi_align.py\n@@ -82,7 +82,7 @@\n         self.sampling_ratio = sampling_ratio\n         self.aligned = aligned\n \n-    def forward(self, input: Tensor, rois: Tensor) -> Tensor:\n+    def forward(self, input: Tensor, rois: Union[Tensor, List[Tensor]]) -> Tensor:\n         return roi_align(input, rois, self.output_size, self.spatial_scale, self.sampling_ratio, self.aligned)\n \n     def __repr__(self) -> str:\ndiff --git a/torchvision/ops/roi_pool.py b/torchvision/ops/roi_pool.py\n--- a/torchvision/ops/roi_pool.py\n+++ b/torchvision/ops/roi_pool.py\n@@ -62,7 +62,7 @@\n         self.output_size = output_size\n         self.spatial_scale = spatial_scale\n \n-    def forward(self, input: Tensor, rois: Tensor) -> Tensor:\n+    def forward(self, input: Tensor, rois: Union[Tensor, List[Tensor]]) -> Tensor:\n         return roi_pool(input, rois, self.output_size, self.spatial_scale)\n \n     def __repr__(self) -> str:\n", "issue": "Inconsistency between RoIPool's forward and roi_pool\n### \ud83d\ude80 The feature\n\nCurrently the functional `roi_pool` method supports both `Tensor` and `List[Tensor]` for boxes, but the module forward function of `RoIPool` expects boxes(rois) to be `Tensor` only. Can we change the function signature to support both? \r\n\r\nThe inconsistency can cause issue during torchscripting, for example:\r\n```\r\nfrom typing import List\r\nimport torch\r\nfrom torch import Tensor\r\nfrom torchvision.ops import RoIPool\r\n\r\nclass Model(torch.nn.Module):\r\n    def __init__(self):\r\n        super().__init__()\r\n        self.pool = RoIPool(output_size=[3,3], spatial_scale=1.0)\r\n\r\n    def forward(self, imgs, boxes: List[Tensor]):\r\n        return self.pool(imgs, boxes)\r\n\r\nmodel = Model()\r\ntorch.jit.script(model)\r\n```\r\nRaise the following error:\r\n\r\n> forward(__torch__.torchvision.ops.roi_pool.RoIPool self, Tensor input, Tensor rois) -> Tensor:\r\n> Expected a value of type 'Tensor' for argument 'rois' but instead found type 'List[Tensor]'.\r\n> Empty lists default to List[Tensor]. Add a variable annotation to the assignment to create an empty list of another type (torch.jit.annotate(List[T, []]) where T is the type of elements in the list for Python 2)\r\n> :\r\n>   File \"<ipython-input-8-9536dd2f0cc1>\", line 12\r\n>     def forward(self, imgs, boxes: List[Tensor]):\r\n>         return self.pool(imgs, boxes)\r\n>                ~~~~~~~~~ <--- HERE\n\n### Motivation, pitch\n\nMake sure the model can be scriptable when using list of boxes as the input.\n\n### Alternatives\n\nOnly support Tensor as the input, user are required to convert bbox of different images into one tensor. Potentially make `_utils.convert_boxes_to_roi_format` public so that users don't need to write the conversion function.\n\n### Additional context\n\n_No response_\n", "before_files": [{"content": "from typing import List, Union\n\nimport torch\nfrom torch import nn, Tensor\nfrom torch.jit.annotations import BroadcastingList2\nfrom torch.nn.modules.utils import _pair\nfrom torchvision.extension import _assert_has_ops\n\nfrom ..utils import _log_api_usage_once\nfrom ._utils import check_roi_boxes_shape, convert_boxes_to_roi_format\n\n\ndef roi_align(\n    input: Tensor,\n    boxes: Union[Tensor, List[Tensor]],\n    output_size: BroadcastingList2[int],\n    spatial_scale: float = 1.0,\n    sampling_ratio: int = -1,\n    aligned: bool = False,\n) -> Tensor:\n    \"\"\"\n    Performs Region of Interest (RoI) Align operator with average pooling, as described in Mask R-CNN.\n\n    Args:\n        input (Tensor[N, C, H, W]): The input tensor, i.e. a batch with ``N`` elements. Each element\n            contains ``C`` feature maps of dimensions ``H x W``.\n            If the tensor is quantized, we expect a batch size of ``N == 1``.\n        boxes (Tensor[K, 5] or List[Tensor[L, 4]]): the box coordinates in (x1, y1, x2, y2)\n            format where the regions will be taken from.\n            The coordinate must satisfy ``0 <= x1 < x2`` and ``0 <= y1 < y2``.\n            If a single Tensor is passed, then the first column should\n            contain the index of the corresponding element in the batch, i.e. a number in ``[0, N - 1]``.\n            If a list of Tensors is passed, then each Tensor will correspond to the boxes for an element i\n            in the batch.\n        output_size (int or Tuple[int, int]): the size of the output (in bins or pixels) after the pooling\n            is performed, as (height, width).\n        spatial_scale (float): a scaling factor that maps the box coordinates to\n            the input coordinates. For example, if your boxes are defined on the scale\n            of a 224x224 image and your input is a 112x112 feature map (resulting from a 0.5x scaling of\n            the original image), you'll want to set this to 0.5. Default: 1.0\n        sampling_ratio (int): number of sampling points in the interpolation grid\n            used to compute the output value of each pooled output bin. If > 0,\n            then exactly ``sampling_ratio x sampling_ratio`` sampling points per bin are used. If\n            <= 0, then an adaptive number of grid points are used (computed as\n            ``ceil(roi_width / output_width)``, and likewise for height). Default: -1\n        aligned (bool): If False, use the legacy implementation.\n            If True, pixel shift the box coordinates it by -0.5 for a better alignment with the two\n            neighboring pixel indices. This version is used in Detectron2\n\n    Returns:\n        Tensor[K, C, output_size[0], output_size[1]]: The pooled RoIs.\n    \"\"\"\n    if not torch.jit.is_scripting() and not torch.jit.is_tracing():\n        _log_api_usage_once(roi_align)\n    _assert_has_ops()\n    check_roi_boxes_shape(boxes)\n    rois = boxes\n    output_size = _pair(output_size)\n    if not isinstance(rois, torch.Tensor):\n        rois = convert_boxes_to_roi_format(rois)\n    return torch.ops.torchvision.roi_align(\n        input, rois, spatial_scale, output_size[0], output_size[1], sampling_ratio, aligned\n    )\n\n\nclass RoIAlign(nn.Module):\n    \"\"\"\n    See :func:`roi_align`.\n    \"\"\"\n\n    def __init__(\n        self,\n        output_size: BroadcastingList2[int],\n        spatial_scale: float,\n        sampling_ratio: int,\n        aligned: bool = False,\n    ):\n        super().__init__()\n        _log_api_usage_once(self)\n        self.output_size = output_size\n        self.spatial_scale = spatial_scale\n        self.sampling_ratio = sampling_ratio\n        self.aligned = aligned\n\n    def forward(self, input: Tensor, rois: Tensor) -> Tensor:\n        return roi_align(input, rois, self.output_size, self.spatial_scale, self.sampling_ratio, self.aligned)\n\n    def __repr__(self) -> str:\n        s = (\n            f\"{self.__class__.__name__}(\"\n            f\"output_size={self.output_size}\"\n            f\", spatial_scale={self.spatial_scale}\"\n            f\", sampling_ratio={self.sampling_ratio}\"\n            f\", aligned={self.aligned}\"\n            f\")\"\n        )\n        return s\n", "path": "torchvision/ops/roi_align.py"}, {"content": "from typing import List, Union\n\nimport torch\nfrom torch import nn, Tensor\nfrom torch.jit.annotations import BroadcastingList2\nfrom torch.nn.modules.utils import _pair\nfrom torchvision.extension import _assert_has_ops\n\nfrom ..utils import _log_api_usage_once\nfrom ._utils import check_roi_boxes_shape, convert_boxes_to_roi_format\n\n\ndef roi_pool(\n    input: Tensor,\n    boxes: Union[Tensor, List[Tensor]],\n    output_size: BroadcastingList2[int],\n    spatial_scale: float = 1.0,\n) -> Tensor:\n    \"\"\"\n    Performs Region of Interest (RoI) Pool operator described in Fast R-CNN\n\n    Args:\n        input (Tensor[N, C, H, W]): The input tensor, i.e. a batch with ``N`` elements. Each element\n            contains ``C`` feature maps of dimensions ``H x W``.\n        boxes (Tensor[K, 5] or List[Tensor[L, 4]]): the box coordinates in (x1, y1, x2, y2)\n            format where the regions will be taken from.\n            The coordinate must satisfy ``0 <= x1 < x2`` and ``0 <= y1 < y2``.\n            If a single Tensor is passed, then the first column should\n            contain the index of the corresponding element in the batch, i.e. a number in ``[0, N - 1]``.\n            If a list of Tensors is passed, then each Tensor will correspond to the boxes for an element i\n            in the batch.\n        output_size (int or Tuple[int, int]): the size of the output after the cropping\n            is performed, as (height, width)\n        spatial_scale (float): a scaling factor that maps the box coordinates to\n            the input coordinates. For example, if your boxes are defined on the scale\n            of a 224x224 image and your input is a 112x112 feature map (resulting from a 0.5x scaling of\n            the original image), you'll want to set this to 0.5. Default: 1.0\n\n    Returns:\n        Tensor[K, C, output_size[0], output_size[1]]: The pooled RoIs.\n    \"\"\"\n    if not torch.jit.is_scripting() and not torch.jit.is_tracing():\n        _log_api_usage_once(roi_pool)\n    _assert_has_ops()\n    check_roi_boxes_shape(boxes)\n    rois = boxes\n    output_size = _pair(output_size)\n    if not isinstance(rois, torch.Tensor):\n        rois = convert_boxes_to_roi_format(rois)\n    output, _ = torch.ops.torchvision.roi_pool(input, rois, spatial_scale, output_size[0], output_size[1])\n    return output\n\n\nclass RoIPool(nn.Module):\n    \"\"\"\n    See :func:`roi_pool`.\n    \"\"\"\n\n    def __init__(self, output_size: BroadcastingList2[int], spatial_scale: float):\n        super().__init__()\n        _log_api_usage_once(self)\n        self.output_size = output_size\n        self.spatial_scale = spatial_scale\n\n    def forward(self, input: Tensor, rois: Tensor) -> Tensor:\n        return roi_pool(input, rois, self.output_size, self.spatial_scale)\n\n    def __repr__(self) -> str:\n        s = f\"{self.__class__.__name__}(output_size={self.output_size}, spatial_scale={self.spatial_scale})\"\n        return s\n", "path": "torchvision/ops/roi_pool.py"}], "after_files": [{"content": "from typing import List, Union\n\nimport torch\nfrom torch import nn, Tensor\nfrom torch.jit.annotations import BroadcastingList2\nfrom torch.nn.modules.utils import _pair\nfrom torchvision.extension import _assert_has_ops\n\nfrom ..utils import _log_api_usage_once\nfrom ._utils import check_roi_boxes_shape, convert_boxes_to_roi_format\n\n\ndef roi_align(\n    input: Tensor,\n    boxes: Union[Tensor, List[Tensor]],\n    output_size: BroadcastingList2[int],\n    spatial_scale: float = 1.0,\n    sampling_ratio: int = -1,\n    aligned: bool = False,\n) -> Tensor:\n    \"\"\"\n    Performs Region of Interest (RoI) Align operator with average pooling, as described in Mask R-CNN.\n\n    Args:\n        input (Tensor[N, C, H, W]): The input tensor, i.e. a batch with ``N`` elements. Each element\n            contains ``C`` feature maps of dimensions ``H x W``.\n            If the tensor is quantized, we expect a batch size of ``N == 1``.\n        boxes (Tensor[K, 5] or List[Tensor[L, 4]]): the box coordinates in (x1, y1, x2, y2)\n            format where the regions will be taken from.\n            The coordinate must satisfy ``0 <= x1 < x2`` and ``0 <= y1 < y2``.\n            If a single Tensor is passed, then the first column should\n            contain the index of the corresponding element in the batch, i.e. a number in ``[0, N - 1]``.\n            If a list of Tensors is passed, then each Tensor will correspond to the boxes for an element i\n            in the batch.\n        output_size (int or Tuple[int, int]): the size of the output (in bins or pixels) after the pooling\n            is performed, as (height, width).\n        spatial_scale (float): a scaling factor that maps the box coordinates to\n            the input coordinates. For example, if your boxes are defined on the scale\n            of a 224x224 image and your input is a 112x112 feature map (resulting from a 0.5x scaling of\n            the original image), you'll want to set this to 0.5. Default: 1.0\n        sampling_ratio (int): number of sampling points in the interpolation grid\n            used to compute the output value of each pooled output bin. If > 0,\n            then exactly ``sampling_ratio x sampling_ratio`` sampling points per bin are used. If\n            <= 0, then an adaptive number of grid points are used (computed as\n            ``ceil(roi_width / output_width)``, and likewise for height). Default: -1\n        aligned (bool): If False, use the legacy implementation.\n            If True, pixel shift the box coordinates it by -0.5 for a better alignment with the two\n            neighboring pixel indices. This version is used in Detectron2\n\n    Returns:\n        Tensor[K, C, output_size[0], output_size[1]]: The pooled RoIs.\n    \"\"\"\n    if not torch.jit.is_scripting() and not torch.jit.is_tracing():\n        _log_api_usage_once(roi_align)\n    _assert_has_ops()\n    check_roi_boxes_shape(boxes)\n    rois = boxes\n    output_size = _pair(output_size)\n    if not isinstance(rois, torch.Tensor):\n        rois = convert_boxes_to_roi_format(rois)\n    return torch.ops.torchvision.roi_align(\n        input, rois, spatial_scale, output_size[0], output_size[1], sampling_ratio, aligned\n    )\n\n\nclass RoIAlign(nn.Module):\n    \"\"\"\n    See :func:`roi_align`.\n    \"\"\"\n\n    def __init__(\n        self,\n        output_size: BroadcastingList2[int],\n        spatial_scale: float,\n        sampling_ratio: int,\n        aligned: bool = False,\n    ):\n        super().__init__()\n        _log_api_usage_once(self)\n        self.output_size = output_size\n        self.spatial_scale = spatial_scale\n        self.sampling_ratio = sampling_ratio\n        self.aligned = aligned\n\n    def forward(self, input: Tensor, rois: Union[Tensor, List[Tensor]]) -> Tensor:\n        return roi_align(input, rois, self.output_size, self.spatial_scale, self.sampling_ratio, self.aligned)\n\n    def __repr__(self) -> str:\n        s = (\n            f\"{self.__class__.__name__}(\"\n            f\"output_size={self.output_size}\"\n            f\", spatial_scale={self.spatial_scale}\"\n            f\", sampling_ratio={self.sampling_ratio}\"\n            f\", aligned={self.aligned}\"\n            f\")\"\n        )\n        return s\n", "path": "torchvision/ops/roi_align.py"}, {"content": "from typing import List, Union\n\nimport torch\nfrom torch import nn, Tensor\nfrom torch.jit.annotations import BroadcastingList2\nfrom torch.nn.modules.utils import _pair\nfrom torchvision.extension import _assert_has_ops\n\nfrom ..utils import _log_api_usage_once\nfrom ._utils import check_roi_boxes_shape, convert_boxes_to_roi_format\n\n\ndef roi_pool(\n    input: Tensor,\n    boxes: Union[Tensor, List[Tensor]],\n    output_size: BroadcastingList2[int],\n    spatial_scale: float = 1.0,\n) -> Tensor:\n    \"\"\"\n    Performs Region of Interest (RoI) Pool operator described in Fast R-CNN\n\n    Args:\n        input (Tensor[N, C, H, W]): The input tensor, i.e. a batch with ``N`` elements. Each element\n            contains ``C`` feature maps of dimensions ``H x W``.\n        boxes (Tensor[K, 5] or List[Tensor[L, 4]]): the box coordinates in (x1, y1, x2, y2)\n            format where the regions will be taken from.\n            The coordinate must satisfy ``0 <= x1 < x2`` and ``0 <= y1 < y2``.\n            If a single Tensor is passed, then the first column should\n            contain the index of the corresponding element in the batch, i.e. a number in ``[0, N - 1]``.\n            If a list of Tensors is passed, then each Tensor will correspond to the boxes for an element i\n            in the batch.\n        output_size (int or Tuple[int, int]): the size of the output after the cropping\n            is performed, as (height, width)\n        spatial_scale (float): a scaling factor that maps the box coordinates to\n            the input coordinates. For example, if your boxes are defined on the scale\n            of a 224x224 image and your input is a 112x112 feature map (resulting from a 0.5x scaling of\n            the original image), you'll want to set this to 0.5. Default: 1.0\n\n    Returns:\n        Tensor[K, C, output_size[0], output_size[1]]: The pooled RoIs.\n    \"\"\"\n    if not torch.jit.is_scripting() and not torch.jit.is_tracing():\n        _log_api_usage_once(roi_pool)\n    _assert_has_ops()\n    check_roi_boxes_shape(boxes)\n    rois = boxes\n    output_size = _pair(output_size)\n    if not isinstance(rois, torch.Tensor):\n        rois = convert_boxes_to_roi_format(rois)\n    output, _ = torch.ops.torchvision.roi_pool(input, rois, spatial_scale, output_size[0], output_size[1])\n    return output\n\n\nclass RoIPool(nn.Module):\n    \"\"\"\n    See :func:`roi_pool`.\n    \"\"\"\n\n    def __init__(self, output_size: BroadcastingList2[int], spatial_scale: float):\n        super().__init__()\n        _log_api_usage_once(self)\n        self.output_size = output_size\n        self.spatial_scale = spatial_scale\n\n    def forward(self, input: Tensor, rois: Union[Tensor, List[Tensor]]) -> Tensor:\n        return roi_pool(input, rois, self.output_size, self.spatial_scale)\n\n    def __repr__(self) -> str:\n        s = f\"{self.__class__.__name__}(output_size={self.output_size}, spatial_scale={self.spatial_scale})\"\n        return s\n", "path": "torchvision/ops/roi_pool.py"}]}