Skip to content

Commit

Permalink
[fbsync] Updated annotation to be a Union of Tensor and List (#4416)
Browse files Browse the repository at this point in the history
Summary:
* Updated annotation to be a Union of Tensor and List

* Updated check_roi_boxes_shape.

Reviewed By: datumbox

Differential Revision: D31268033

fbshipit-source-id: 38f7c4c356862c8cd7785460a6a7a73647e9f519
  • Loading branch information
NicolasHug authored and facebook-github-bot committed Sep 30, 2021
1 parent c92ebdc commit 66724be
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions torchvision/ops/_utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import torch
from torch import Tensor
from typing import List
from typing import List, Union


def _cat(tensors: List[Tensor], dim: int = 0) -> Tensor:
Expand All @@ -24,7 +24,7 @@ def convert_boxes_to_roi_format(boxes: List[Tensor]) -> Tensor:
return rois


def check_roi_boxes_shape(boxes: Tensor):
def check_roi_boxes_shape(boxes: Union[Tensor, List[Tensor]]):
if isinstance(boxes, (list, tuple)):
for _tensor in boxes:
assert _tensor.size(1) == 4, \
Expand Down
7 changes: 4 additions & 3 deletions torchvision/ops/roi_align.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from typing import List, Union

import torch
from torch import nn, Tensor

from torch.nn.modules.utils import _pair
from torch.jit.annotations import BroadcastingList2

from torchvision.extension import _assert_has_ops

from ._utils import convert_boxes_to_roi_format, check_roi_boxes_shape


def roi_align(
input: Tensor,
boxes: Tensor,
boxes: Union[Tensor, List[Tensor]],
output_size: BroadcastingList2[int],
spatial_scale: float = 1.0,
sampling_ratio: int = -1,
Expand Down
7 changes: 4 additions & 3 deletions torchvision/ops/roi_pool.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from typing import List, Union

import torch
from torch import nn, Tensor

from torch.nn.modules.utils import _pair
from torch.jit.annotations import BroadcastingList2

from torchvision.extension import _assert_has_ops

from ._utils import convert_boxes_to_roi_format, check_roi_boxes_shape


def roi_pool(
input: Tensor,
boxes: Tensor,
boxes: Union[Tensor, List[Tensor]],
output_size: BroadcastingList2[int],
spatial_scale: float = 1.0,
) -> Tensor:
Expand Down

0 comments on commit 66724be

Please sign in to comment.