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
218deb71
Commit
218deb71
authored
Jun 28, 2022
by
A. Unique TensorFlower
Browse files
Internal change
PiperOrigin-RevId: 457852983
parent
e4c6ae27
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
0 deletions
+47
-0
official/vision/ops/preprocess_ops.py
official/vision/ops/preprocess_ops.py
+47
-0
No files found.
official/vision/ops/preprocess_ops.py
View file @
218deb71
...
@@ -638,6 +638,53 @@ def random_horizontal_flip(image, normalized_boxes=None, masks=None, seed=1):
...
@@ -638,6 +638,53 @@ def random_horizontal_flip(image, normalized_boxes=None, masks=None, seed=1):
return
image
,
normalized_boxes
,
masks
return
image
,
normalized_boxes
,
masks
def
random_horizontal_flip_with_roi
(
image
:
tf
.
Tensor
,
boxes
:
Optional
[
tf
.
Tensor
]
=
None
,
masks
:
Optional
[
tf
.
Tensor
]
=
None
,
roi_boxes
:
Optional
[
tf
.
Tensor
]
=
None
,
seed
:
int
=
1
)
->
Tuple
[
tf
.
Tensor
,
Optional
[
tf
.
Tensor
],
Optional
[
tf
.
Tensor
],
Optional
[
tf
.
Tensor
]]:
"""Randomly flips input image and bounding boxes.
Extends preprocess_ops.random_horizontal_flip to also flip roi_boxes used
by ViLD.
Args:
image: `tf.Tensor`, the image to apply the random flip.
boxes: `tf.Tensor` or `None`, boxes corresponding to the image.
masks: `tf.Tensor` or `None`, masks corresponding to the image.
roi_boxes: `tf.Tensor` or `None`, RoIs corresponding to the image.
seed: Seed for Tensorflow's random number generator.
Returns:
image: `tf.Tensor`, flipped image.
boxes: `tf.Tensor` or `None`, flipped boxes corresponding to the image.
masks: `tf.Tensor` or `None`, flipped masks corresponding to the image.
roi_boxes: `tf.Tensor` or `None`, flipped RoIs corresponding to the image.
"""
with
tf
.
name_scope
(
'random_horizontal_flip'
):
do_flip
=
tf
.
greater
(
tf
.
random
.
uniform
([],
seed
=
seed
),
0.5
)
image
=
tf
.
cond
(
do_flip
,
lambda
:
horizontal_flip_image
(
image
),
lambda
:
image
)
if
boxes
is
not
None
:
boxes
=
tf
.
cond
(
do_flip
,
lambda
:
horizontal_flip_boxes
(
boxes
),
lambda
:
boxes
)
if
masks
is
not
None
:
masks
=
tf
.
cond
(
do_flip
,
lambda
:
horizontal_flip_masks
(
masks
),
lambda
:
masks
)
if
roi_boxes
is
not
None
:
roi_boxes
=
tf
.
cond
(
do_flip
,
lambda
:
horizontal_flip_boxes
(
roi_boxes
),
lambda
:
roi_boxes
)
return
image
,
boxes
,
masks
,
roi_boxes
def
color_jitter
(
image
:
tf
.
Tensor
,
def
color_jitter
(
image
:
tf
.
Tensor
,
brightness
:
Optional
[
float
]
=
0.
,
brightness
:
Optional
[
float
]
=
0.
,
contrast
:
Optional
[
float
]
=
0.
,
contrast
:
Optional
[
float
]
=
0.
,
...
...
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