Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Shreyan Chowdhury
moodwalk
Commits
6ca30b70
Commit
6ca30b70
authored
Sep 11, 2019
by
Verena Praher
Browse files
add augmentation functions based on SpecAugment
parent
f3f01a50
Changes
1
Hide whitespace changes
Inline
Side-by-side
datasets/augment.py
0 → 100644
View file @
6ca30b70
import
random
def
freq_mask
(
spec
,
F
=
30
,
num_masks
=
1
,
replace_with_zero
=
False
):
cloned
=
spec
.
clone
()
num_mel_channels
=
cloned
.
shape
[
1
]
for
i
in
range
(
0
,
num_masks
):
f
=
random
.
randrange
(
0
,
F
)
f_zero
=
random
.
randrange
(
0
,
num_mel_channels
-
f
)
# avoids randrange error if values are equal and range is empty
if
(
f_zero
==
f_zero
+
f
):
return
cloned
mask_end
=
random
.
randrange
(
f_zero
,
f_zero
+
f
)
if
(
replace_with_zero
):
cloned
[
0
][
f_zero
:
mask_end
]
=
0
else
:
cloned
[
0
][
f_zero
:
mask_end
]
=
cloned
.
mean
()
return
cloned
def
time_mask
(
spec
,
T
=
40
,
num_masks
=
1
,
replace_with_zero
=
False
):
cloned
=
spec
.
clone
()
len_spectro
=
cloned
.
shape
[
2
]
for
i
in
range
(
0
,
num_masks
):
t
=
random
.
randrange
(
0
,
T
)
t_zero
=
random
.
randrange
(
0
,
len_spectro
-
t
)
# avoids randrange error if values are equal and range is empty
if
(
t_zero
==
t_zero
+
t
):
return
cloned
mask_end
=
random
.
randrange
(
t_zero
,
t_zero
+
t
)
if
(
replace_with_zero
):
cloned
[
0
][:,
t_zero
:
mask_end
]
=
0
else
:
cloned
[
0
][:,
t_zero
:
mask_end
]
=
cloned
.
mean
()
return
cloned
\ No newline at end of file
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