Skip to content

Commit 106fc31

Browse files
NicolasHugfacebook-github-bot
authored andcommitted
[fbsync] Use Sequence for parameters type checking in transforms.RandomErase (#8615)
Summary: Co-authored-by: Nicolas Hug <nh.nicolas.hug@gmail.com> Reviewed By: ahmadsharif1 Differential Revision: D62032048 fbshipit-source-id: 274a8c8b5fe150103755ec84f2791b39fb3f5d60
1 parent 7cf2ba5 commit 106fc31

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

torchvision/transforms/transforms.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -1649,9 +1649,9 @@ def __init__(self, p=0.5, scale=(0.02, 0.33), ratio=(0.3, 3.3), value=0, inplace
16491649
raise TypeError("Argument value should be either a number or str or a sequence")
16501650
if isinstance(value, str) and value != "random":
16511651
raise ValueError("If value is str, it should be 'random'")
1652-
if not isinstance(scale, (tuple, list)):
1652+
if not isinstance(scale, Sequence):
16531653
raise TypeError("Scale should be a sequence")
1654-
if not isinstance(ratio, (tuple, list)):
1654+
if not isinstance(ratio, Sequence):
16551655
raise TypeError("Ratio should be a sequence")
16561656
if (scale[0] > scale[1]) or (ratio[0] > ratio[1]):
16571657
warnings.warn("Scale and ratio should be of kind (min, max)")

torchvision/transforms/v2/_augment.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import math
22
import numbers
33
import warnings
4-
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
4+
from typing import Any, Callable, Dict, List, Optional, Sequence, Union
55

66
import PIL.Image
77
import torch
@@ -56,8 +56,8 @@ def _extract_params_for_v1_transform(self) -> Dict[str, Any]:
5656
def __init__(
5757
self,
5858
p: float = 0.5,
59-
scale: Tuple[float, float] = (0.02, 0.33),
60-
ratio: Tuple[float, float] = (0.3, 3.3),
59+
scale: Sequence[float] = (0.02, 0.33),
60+
ratio: Sequence[float] = (0.3, 3.3),
6161
value: float = 0.0,
6262
inplace: bool = False,
6363
):
@@ -66,9 +66,9 @@ def __init__(
6666
raise TypeError("Argument value should be either a number or str or a sequence")
6767
if isinstance(value, str) and value != "random":
6868
raise ValueError("If value is str, it should be 'random'")
69-
if not isinstance(scale, (tuple, list)):
69+
if not isinstance(scale, Sequence):
7070
raise TypeError("Scale should be a sequence")
71-
if not isinstance(ratio, (tuple, list)):
71+
if not isinstance(ratio, Sequence):
7272
raise TypeError("Ratio should be a sequence")
7373
if (scale[0] > scale[1]) or (ratio[0] > ratio[1]):
7474
warnings.warn("Scale and ratio should be of kind (min, max)")

0 commit comments

Comments
 (0)