Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tom Rink
python
Commits
9d89ec15
Commit
9d89ec15
authored
1 year ago
by
tomrink
Browse files
Options
Downloads
Patches
Plain Diff
snapshot...
parent
25fa822f
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/util/augment.py
+44
-0
44 additions, 0 deletions
modules/util/augment.py
with
44 additions
and
0 deletions
modules/util/augment.py
+
44
−
0
View file @
9d89ec15
...
@@ -87,3 +87,47 @@ def augment_icing():
...
@@ -87,3 +87,47 @@ def augment_icing():
partial
(
augment_steps_fn
,
data
,
data_b
,
label
))
partial
(
augment_steps_fn
,
data
,
data_b
,
label
))
return
augment_fn
return
augment_fn
def
augment_image_3arg
():
"""
Helper function used for augmentation of images in the dataset.
Returns:
tf.data.Dataset mappable function for image augmentation
"""
def
augment_fn
(
data
,
data_b
,
label
,
*
args
,
**
kwargs
):
# Augmenting data (~ 80%)
def
augment_steps_fn
(
data
,
data_b
,
label
):
# Randomly rotating image (~50%)
def
rotate_fn
(
data
,
data_b
,
label
):
times
=
tf
.
random
.
uniform
(
minval
=
1
,
maxval
=
4
,
dtype
=
tf
.
int32
,
shape
=
[])
return
(
tf
.
image
.
rot90
(
data
,
times
),
tf
.
image
.
rot90
(
data_b
,
times
),
tf
.
image
.
rot90
(
label
,
times
))
data
,
data_b
,
label
=
tf
.
cond
(
tf
.
less_equal
(
tf
.
random
.
uniform
([]),
0.5
),
lambda
:
rotate_fn
(
data
,
data_b
,
label
),
lambda
:
(
data
,
data_b
,
label
))
# Randomly flipping image (~50%)
def
flip_fn
(
data
,
data_b
,
label
):
return
(
tf
.
image
.
flip_left_right
(
data
),
tf
.
image
.
flip_left_right
(
data_b
),
tf
.
image
.
flip_left_right
(
label
))
data
,
data_b
,
label
=
tf
.
cond
(
tf
.
less_equal
(
tf
.
random
.
uniform
([]),
0.5
),
lambda
:
flip_fn
(
data
,
data_b
,
label
),
lambda
:
(
data
,
data_b
,
label
))
return
data
,
data_b
,
label
# Randomly returning unchanged data (~20%)
return
tf
.
cond
(
tf
.
less_equal
(
tf
.
random
.
uniform
([]),
0.2
),
lambda
:
(
data
,
data_b
,
label
),
partial
(
augment_steps_fn
,
data
,
data_b
,
label
))
return
augment_fn
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment