Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cdx-submissions
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
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
yoyololicon
cdx-submissions
Commits
20b31367
Commit
20b31367
authored
2 years ago
by
Chin-Yun Yu
Browse files
Options
Downloads
Patches
Plain Diff
try wiener filtering
parent
1b41576a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
my_submission/hdemucs.py
+52
-1
52 additions, 1 deletion
my_submission/hdemucs.py
my_submission/user_config.py
+2
-2
2 additions, 2 deletions
my_submission/user_config.py
with
54 additions
and
3 deletions
my_submission/hdemucs.py
+
52
−
1
View file @
20b31367
import
numpy
as
np
import
numpy
as
np
import
torch
import
torch
import
torch.nn.functional
as
F
from
importlib
import
import_module
from
importlib
import
import_module
from
.identity_separation_model
import
IdentitySeparationModel
from
.identity_separation_model
import
IdentitySeparationModel
import
os
import
os
import
yaml
import
yaml
from
aimless.utils
import
MWF
from
torchaudio.transforms
import
Spectrogram
,
InverseSpectrogram
class
HDemucs
(
IdentitySeparationModel
):
class
HDemucs
(
IdentitySeparationModel
):
...
@@ -12,7 +15,7 @@ class HDemucs(IdentitySeparationModel):
...
@@ -12,7 +15,7 @@ class HDemucs(IdentitySeparationModel):
"""
"""
version_path
=
"
./my_submission/lightning_logs/hdemucs-64/
"
version_path
=
"
./my_submission/lightning_logs/hdemucs-64/
"
ckpt_name
=
"
epoch=
3
-step=
52
000.ckpt
"
ckpt_name
=
"
epoch=
2
-step=
40
000.ckpt
"
device
=
torch
.
device
(
"
cuda
"
if
torch
.
cuda
.
is_available
()
else
"
cpu
"
)
device
=
torch
.
device
(
"
cuda
"
if
torch
.
cuda
.
is_available
()
else
"
cpu
"
)
instruments_idx
=
{
instruments_idx
=
{
"
dialog
"
:
2
,
"
dialog
"
:
2
,
...
@@ -72,3 +75,51 @@ class HDemucs(IdentitySeparationModel):
...
@@ -72,3 +75,51 @@ class HDemucs(IdentitySeparationModel):
output_sample_rates
[
instrument
]
=
sample_rate
output_sample_rates
[
instrument
]
=
sample_rate
return
separated_music_arrays
,
output_sample_rates
return
separated_music_arrays
,
output_sample_rates
class
HDemucsMWF
(
HDemucs
):
n_fft
=
4096
hop_length
=
1024
def
__init__
(
self
):
super
().
__init__
()
self
.
spec
=
Spectrogram
(
n_fft
=
self
.
n_fft
,
hop_length
=
self
.
hop_length
,
power
=
None
).
to
(
self
.
device
)
self
.
inv_spec
=
InverseSpectrogram
(
n_fft
=
self
.
n_fft
,
hop_length
=
self
.
hop_length
).
to
(
self
.
device
)
self
.
mwf
=
MWF
(
softmask
=
True
).
to
(
self
.
device
)
@torch.no_grad
()
def
separate_music_file
(
self
,
mixed_sound_array
,
sample_rate
):
mixed_sound_array
=
(
torch
.
from_numpy
(
mixed_sound_array
.
T
).
float
().
to
(
self
.
device
).
unsqueeze
(
1
)
)
# B, C, S, T
seperated
=
self
.
hdemucs
(
mixed_sound_array
).
transpose
(
0
,
2
)
# B, S, C, T
mask_hat
=
self
.
spec
(
seperated
).
abs
()
# B, S, C, F, T
mix_spec
=
self
.
spec
(
mixed_sound_array
.
transpose
(
0
,
1
))
# B, C, F, T
seperated
=
self
.
inv_spec
(
self
.
mwf
(
mask_hat
,
mix_spec
)).
squeeze
().
cpu
()
if
seperated
.
shape
[
-
1
]
<
mixed_sound_array
.
shape
[
-
1
]:
seperated
=
F
.
pad
(
seperated
,
(
0
,
mixed_sound_array
.
shape
[
-
1
]
-
seperated
.
shape
[
-
1
])
)
seperated
=
seperated
.
transpose
(
1
,
2
).
numpy
()
# input_length = len(left_mixed_arr)
separated_music_arrays
=
{}
output_sample_rates
=
{}
for
instrument
in
self
.
instruments
:
separated_music_arrays
[
instrument
]
=
seperated
[
self
.
instruments_idx
[
instrument
]
]
output_sample_rates
[
instrument
]
=
sample_rate
return
separated_music_arrays
,
output_sample_rates
This diff is collapsed.
Click to expand it.
my_submission/user_config.py
+
2
−
2
View file @
20b31367
...
@@ -5,6 +5,6 @@
...
@@ -5,6 +5,6 @@
# MySeparationModel = ScaledIdentitySeparationModel
# MySeparationModel = ScaledIdentitySeparationModel
# from my_submission.cocktail_fork_separation_model import CocktailForkSeparationModel
# from my_submission.cocktail_fork_separation_model import CocktailForkSeparationModel
from
my_submission.hdemucs
import
HDemucs
from
my_submission.hdemucs
import
HDemucs
,
HDemucsMWF
MySeparationModel
=
HDemucs
MySeparationModel
=
HDemucs
MWF
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