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
ModelZoo
ResNet50_tensorflow
Commits
6c1a6676
Commit
6c1a6676
authored
May 24, 2021
by
Fan Yang
Committed by
A. Unique TensorFlower
May 24, 2021
Browse files
Internal change
PiperOrigin-RevId: 375526479
parent
3fa47266
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
3 deletions
+17
-3
official/vision/beta/configs/common.py
official/vision/beta/configs/common.py
+1
-0
official/vision/beta/dataloaders/classification_input.py
official/vision/beta/dataloaders/classification_input.py
+2
-1
official/vision/beta/ops/augment.py
official/vision/beta/ops/augment.py
+14
-2
No files found.
official/vision/beta/configs/common.py
View file @
6c1a6676
...
...
@@ -31,6 +31,7 @@ class RandAugment(hyperparams.Config):
magnitude
:
float
=
10
cutout_const
:
float
=
40
translate_const
:
float
=
10
prob_to_apply
:
Optional
[
float
]
=
None
@
dataclasses
.
dataclass
...
...
official/vision/beta/dataloaders/classification_input.py
View file @
6c1a6676
...
...
@@ -109,7 +109,8 @@ class Parser(parser.Parser):
num_layers
=
aug_type
.
randaug
.
num_layers
,
magnitude
=
aug_type
.
randaug
.
magnitude
,
cutout_const
=
aug_type
.
randaug
.
cutout_const
,
translate_const
=
aug_type
.
randaug
.
translate_const
)
translate_const
=
aug_type
.
randaug
.
translate_const
,
prob_to_apply
=
aug_type
.
randaug
.
prob_to_apply
)
else
:
raise
ValueError
(
'Augmentation policy {} not supported.'
.
format
(
aug_type
.
type
))
...
...
official/vision/beta/ops/augment.py
View file @
6c1a6676
...
...
@@ -1183,7 +1183,8 @@ class RandAugment(ImageAugment):
num_layers
:
int
=
2
,
magnitude
:
float
=
10.
,
cutout_const
:
float
=
40.
,
translate_const
:
float
=
100.
):
translate_const
:
float
=
100.
,
prob_to_apply
:
Optional
[
float
]
=
None
):
"""Applies the RandAugment policy to images.
Args:
...
...
@@ -1195,6 +1196,8 @@ class RandAugment(ImageAugment):
[5, 10].
cutout_const: multiplier for applying cutout.
translate_const: multiplier for applying translation.
prob_to_apply: The probability to apply the selected augmentation at each
layer.
"""
super
(
RandAugment
,
self
).
__init__
()
...
...
@@ -1202,6 +1205,7 @@ class RandAugment(ImageAugment):
self
.
magnitude
=
float
(
magnitude
)
self
.
cutout_const
=
float
(
cutout_const
)
self
.
translate_const
=
float
(
translate_const
)
self
.
prob_to_apply
=
prob_to_apply
self
.
available_ops
=
[
'AutoContrast'
,
'Equalize'
,
'Invert'
,
'Rotate'
,
'Posterize'
,
'Solarize'
,
'Color'
,
'Contrast'
,
'Brightness'
,
'Sharpness'
,
'ShearX'
,
'ShearY'
,
...
...
@@ -1226,6 +1230,8 @@ class RandAugment(ImageAugment):
replace_value
=
[
128
]
*
3
min_prob
,
max_prob
=
0.2
,
0.8
aug_image
=
image
for
_
in
range
(
self
.
num_layers
):
op_to_select
=
tf
.
random
.
uniform
([],
maxval
=
len
(
self
.
available_ops
)
+
1
,
...
...
@@ -1247,10 +1253,16 @@ class RandAugment(ImageAugment):
image
,
*
selected_args
)))
# pylint:enable=g-long-lambda
image
=
tf
.
switch_case
(
aug_
image
=
tf
.
switch_case
(
branch_index
=
op_to_select
,
branch_fns
=
branch_fns
,
default
=
lambda
:
tf
.
identity
(
image
))
if
self
.
prob_to_apply
is
not
None
:
aug_image
=
tf
.
cond
(
tf
.
random
.
uniform
(
shape
=
[],
dtype
=
tf
.
float32
)
<
self
.
prob_to_apply
,
lambda
:
tf
.
identity
(
aug_image
),
lambda
:
tf
.
identity
(
image
))
image
=
aug_image
image
=
tf
.
cast
(
image
,
dtype
=
input_image_type
)
return
image
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