Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
vision
Commits
60c78f28
Unverified
Commit
60c78f28
authored
Jan 26, 2023
by
Philip Meier
Committed by
GitHub
Jan 26, 2023
Browse files
make RandomErasing scriptable for integer value (#7134)
parent
5dd95944
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
8 deletions
+18
-8
test/test_transforms_tensor.py
test/test_transforms_tensor.py
+11
-1
torchvision/prototype/transforms/_augment.py
torchvision/prototype/transforms/_augment.py
+4
-4
torchvision/transforms/transforms.py
torchvision/transforms/transforms.py
+3
-3
No files found.
test/test_transforms_tensor.py
View file @
60c78f28
...
@@ -672,7 +672,17 @@ def test_autoaugment__op_apply_shear(interpolation, mode):
...
@@ -672,7 +672,17 @@ def test_autoaugment__op_apply_shear(interpolation, mode):
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_gpu
())
@
pytest
.
mark
.
parametrize
(
"device"
,
cpu_and_gpu
())
@
pytest
.
mark
.
parametrize
(
@
pytest
.
mark
.
parametrize
(
"config"
,
"config"
,
[{
"value"
:
0.2
},
{
"value"
:
"random"
},
{
"value"
:
(
0.2
,
0.2
,
0.2
)},
{
"value"
:
"random"
,
"ratio"
:
(
0.1
,
0.2
)}],
[
{},
{
"value"
:
1
},
{
"value"
:
0.2
},
{
"value"
:
"random"
},
{
"value"
:
(
1
,
1
,
1
)},
{
"value"
:
(
0.2
,
0.2
,
0.2
)},
{
"value"
:
[
1
,
1
,
1
]},
{
"value"
:
[
0.2
,
0.2
,
0.2
]},
{
"value"
:
"random"
,
"ratio"
:
(
0.1
,
0.2
)},
],
)
)
def
test_random_erasing
(
device
,
config
):
def
test_random_erasing
(
device
,
config
):
tensor
,
_
=
_create_data
(
24
,
32
,
channels
=
3
,
device
=
device
)
tensor
,
_
=
_create_data
(
24
,
32
,
channels
=
3
,
device
=
device
)
...
...
torchvision/prototype/transforms/_augment.py
View file @
60c78f28
...
@@ -23,7 +23,7 @@ class RandomErasing(_RandomApplyTransform):
...
@@ -23,7 +23,7 @@ class RandomErasing(_RandomApplyTransform):
p
:
float
=
0.5
,
p
:
float
=
0.5
,
scale
:
Tuple
[
float
,
float
]
=
(
0.02
,
0.33
),
scale
:
Tuple
[
float
,
float
]
=
(
0.02
,
0.33
),
ratio
:
Tuple
[
float
,
float
]
=
(
0.3
,
3.3
),
ratio
:
Tuple
[
float
,
float
]
=
(
0.3
,
3.3
),
value
:
float
=
0
,
value
:
float
=
0.
0
,
inplace
:
bool
=
False
,
inplace
:
bool
=
False
,
):
):
super
().
__init__
(
p
=
p
)
super
().
__init__
(
p
=
p
)
...
@@ -42,11 +42,11 @@ class RandomErasing(_RandomApplyTransform):
...
@@ -42,11 +42,11 @@ class RandomErasing(_RandomApplyTransform):
self
.
scale
=
scale
self
.
scale
=
scale
self
.
ratio
=
ratio
self
.
ratio
=
ratio
if
isinstance
(
value
,
(
int
,
float
)):
if
isinstance
(
value
,
(
int
,
float
)):
self
.
value
=
[
value
]
self
.
value
=
[
float
(
value
)
]
elif
isinstance
(
value
,
str
):
elif
isinstance
(
value
,
str
):
self
.
value
=
None
self
.
value
=
None
elif
isinstance
(
value
,
tuple
):
elif
isinstance
(
value
,
(
list
,
tuple
)
)
:
self
.
value
=
list
(
value
)
self
.
value
=
[
float
(
v
)
for
v
in
value
]
else
:
else
:
self
.
value
=
value
self
.
value
=
value
self
.
inplace
=
inplace
self
.
inplace
=
inplace
...
...
torchvision/transforms/transforms.py
View file @
60c78f28
...
@@ -1713,11 +1713,11 @@ class RandomErasing(torch.nn.Module):
...
@@ -1713,11 +1713,11 @@ class RandomErasing(torch.nn.Module):
# cast self.value to script acceptable type
# cast self.value to script acceptable type
if
isinstance
(
self
.
value
,
(
int
,
float
)):
if
isinstance
(
self
.
value
,
(
int
,
float
)):
value
=
[
self
.
value
]
value
=
[
float
(
self
.
value
)
]
elif
isinstance
(
self
.
value
,
str
):
elif
isinstance
(
self
.
value
,
str
):
value
=
None
value
=
None
elif
isinstance
(
self
.
value
,
tuple
):
elif
isinstance
(
self
.
value
,
(
list
,
tuple
)
)
:
value
=
list
(
self
.
value
)
value
=
[
float
(
v
)
for
v
in
self
.
value
]
else
:
else
:
value
=
self
.
value
value
=
self
.
value
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment