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
c631af40
Commit
c631af40
authored
Oct 01, 2021
by
Vishnu Banna
Browse files
datapipeline fixes
parent
d5ae12e1
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
13 deletions
+18
-13
official/vision/beta/projects/yolo/dataloaders/yolo_input.py
official/vision/beta/projects/yolo/dataloaders/yolo_input.py
+3
-2
official/vision/beta/projects/yolo/ops/mosaic.py
official/vision/beta/projects/yolo/ops/mosaic.py
+8
-4
official/vision/beta/projects/yolo/ops/preprocessing_ops.py
official/vision/beta/projects/yolo/ops/preprocessing_ops.py
+7
-7
No files found.
official/vision/beta/projects/yolo/dataloaders/yolo_input.py
View file @
c631af40
...
...
@@ -147,6 +147,7 @@ class Parser(parser.Parser):
# Set the per level values needed for operation
self
.
_darknet
=
darknet
self
.
_area_thresh
=
area_thresh
self
.
_level_limits
=
level_limits
self
.
_seed
=
seed
self
.
_dtype
=
dtype
...
...
@@ -259,7 +260,7 @@ class Parser(parser.Parser):
self
.
_aug_rand_saturation
,
self
.
_aug_rand_brightness
,
seed
=
self
.
_seed
,
darknet
=
self
.
_darknet
)
darknet
=
self
.
_darknet
or
self
.
_level_limits
is
not
None
)
# Cast the image to the selcted datatype.
image
,
labels
=
self
.
_build_label
(
...
...
official/vision/beta/projects/yolo/ops/mosaic.py
View file @
c631af40
...
...
@@ -14,7 +14,6 @@
"""Mosaic op."""
import
random
import
tensorflow
as
tf
import
tensorflow_addons
as
tfa
...
...
@@ -22,7 +21,6 @@ from official.vision.beta.ops import box_ops
from
official.vision.beta.ops
import
preprocess_ops
from
official.vision.beta.projects.yolo.ops
import
preprocessing_ops
class
Mosaic
:
"""Stitch together sets of 4 images to generate samples with more boxes."""
...
...
@@ -211,6 +209,7 @@ class Mosaic:
boxes
,
classes
,
is_crowd
,
area
=
self
.
_select_ind
(
inds
,
boxes
,
classes
,
# pylint:disable=unbalanced-tuple-unpacking
is_crowd
,
area
)
# warp and scale the fully stitched sample
image
,
_
,
affine
=
preprocessing_ops
.
affine_warp_image
(
image
,
[
self
.
_output_size
[
0
],
self
.
_output_size
[
1
]],
...
...
@@ -325,6 +324,11 @@ class Mosaic:
else
:
return
self
.
_add_param
(
noop
)
def
_beta
(
self
,
alpha
,
beta
):
a
=
tf
.
random
.
gamma
([],
alpha
)
b
=
tf
.
random
.
gamma
([],
beta
)
return
b
/
(
a
+
b
)
def
_mixup
(
self
,
one
,
two
):
"""Blend together 2 images for the mixup data augmentation."""
if
self
.
_mixup_frequency
>=
1.0
:
...
...
@@ -337,8 +341,8 @@ class Mosaic:
if
domo
>=
(
1
-
self
.
_mixup_frequency
):
sample
=
one
otype
=
one
[
'image'
].
dtype
r
=
preprocessing_ops
.
random_uniform_strong
(
0.4
,
0.6
,
tf
.
float32
,
seed
=
self
.
_seed
)
r
=
self
.
_beta
(
8.0
,
8.0
)
sample
[
'image'
]
=
(
r
*
tf
.
cast
(
one
[
'image'
],
tf
.
float32
)
+
(
1
-
r
)
*
tf
.
cast
(
two
[
'image'
],
tf
.
float32
))
...
...
official/vision/beta/projects/yolo/ops/preprocessing_ops.py
View file @
c631af40
...
...
@@ -170,14 +170,14 @@ def get_image_shape(image):
def
_augment_hsv_darknet
(
image
,
rh
,
rs
,
rv
,
seed
=
None
):
"""Randomize the hue, saturation, and brightness via the darknet method."""
if
rh
>
0.0
:
delta
=
random_uniform_strong
(
-
rh
,
rh
,
seed
=
seed
)
image
=
tf
.
image
.
adjust_hue
(
image
,
delta
)
delta
h
=
random_uniform_strong
(
-
rh
,
rh
,
seed
=
seed
)
image
=
tf
.
image
.
adjust_hue
(
image
,
delta
h
)
if
rs
>
0.0
:
delta
=
random_scale
(
rs
,
seed
=
seed
)
image
=
tf
.
image
.
adjust_saturation
(
image
,
delta
)
delta
s
=
random_scale
(
rs
,
seed
=
seed
)
image
=
tf
.
image
.
adjust_saturation
(
image
,
delta
s
)
if
rv
>
0.0
:
delta
=
random_scale
(
rv
,
seed
=
seed
)
image
*=
delta
delta
v
=
random_scale
(
rv
,
seed
=
seed
)
image
*=
tf
.
cast
(
deltav
,
image
.
dtype
)
# clip the values of the image between 0.0 and 1.0
image
=
tf
.
clip_by_value
(
image
,
0.0
,
1.0
)
...
...
@@ -719,7 +719,7 @@ def affine_warp_boxes(affine, boxes, output_size, box_history):
return
tf
.
stack
([
y_min
,
x_min
,
y_max
,
x_max
],
axis
=-
1
)
def
_aug_boxes
(
affine_matrix
,
box
):
"""Apply an affine transformation matrix M to the boxes augment
e
boxes."""
"""Apply an affine transformation matrix M to the boxes augment boxes."""
corners
=
_get_corners
(
box
)
corners
=
tf
.
reshape
(
corners
,
[
-
1
,
4
,
2
])
z
=
tf
.
expand_dims
(
tf
.
ones_like
(
corners
[...,
1
]),
axis
=-
1
)
...
...
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