Skip to content

Commit

Permalink
[fbsync] Use Sequence for parameters type checking in transforms.Rand…
Browse files Browse the repository at this point in the history
…omErase (#8615)

Summary: Co-authored-by: Nicolas Hug <nh.nicolas.hug@gmail.com>

Reviewed By: ahmadsharif1

Differential Revision: D62032048

fbshipit-source-id: 274a8c8b5fe150103755ec84f2791b39fb3f5d60
  • Loading branch information
NicolasHug authored and facebook-github-bot committed Sep 2, 2024
1 parent 7cf2ba5 commit 106fc31
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions torchvision/transforms/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1649,9 +1649,9 @@ def __init__(self, p=0.5, scale=(0.02, 0.33), ratio=(0.3, 3.3), value=0, inplace
raise TypeError("Argument value should be either a number or str or a sequence")
if isinstance(value, str) and value != "random":
raise ValueError("If value is str, it should be 'random'")
if not isinstance(scale, (tuple, list)):
if not isinstance(scale, Sequence):
raise TypeError("Scale should be a sequence")
if not isinstance(ratio, (tuple, list)):
if not isinstance(ratio, Sequence):
raise TypeError("Ratio should be a sequence")
if (scale[0] > scale[1]) or (ratio[0] > ratio[1]):
warnings.warn("Scale and ratio should be of kind (min, max)")
Expand Down
10 changes: 5 additions & 5 deletions torchvision/transforms/v2/_augment.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import math
import numbers
import warnings
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
from typing import Any, Callable, Dict, List, Optional, Sequence, Union

import PIL.Image
import torch
Expand Down Expand Up @@ -56,8 +56,8 @@ def _extract_params_for_v1_transform(self) -> Dict[str, Any]:
def __init__(
self,
p: float = 0.5,
scale: Tuple[float, float] = (0.02, 0.33),
ratio: Tuple[float, float] = (0.3, 3.3),
scale: Sequence[float] = (0.02, 0.33),
ratio: Sequence[float] = (0.3, 3.3),
value: float = 0.0,
inplace: bool = False,
):
Expand All @@ -66,9 +66,9 @@ def __init__(
raise TypeError("Argument value should be either a number or str or a sequence")
if isinstance(value, str) and value != "random":
raise ValueError("If value is str, it should be 'random'")
if not isinstance(scale, (tuple, list)):
if not isinstance(scale, Sequence):
raise TypeError("Scale should be a sequence")
if not isinstance(ratio, (tuple, list)):
if not isinstance(ratio, Sequence):
raise TypeError("Ratio should be a sequence")
if (scale[0] > scale[1]) or (ratio[0] > ratio[1]):
warnings.warn("Scale and ratio should be of kind (min, max)")
Expand Down

0 comments on commit 106fc31

Please sign in to comment.