Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Opus
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Xiph.Org
Opus
Commits
0459a572
Unverified
Commit
0459a572
authored
1 year ago
by
Jan Buethe
Browse files
Options
Downloads
Patches
Plain Diff
updated PitchDNN export script
parent
ce286958
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Pipeline
#4099
passed
1 year ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
dnn/torch/neural-pitch/export_neuralpitch_weights.py
+29
-17
29 additions, 17 deletions
dnn/torch/neural-pitch/export_neuralpitch_weights.py
with
29 additions
and
17 deletions
dnn/torch/neural-pitch/export_neuralpitch_weights.py
+
29
−
17
View file @
0459a572
...
...
@@ -44,7 +44,7 @@ args = parser.parse_args()
import
torch
import
numpy
as
np
from
models
import
large_if_ccode
from
models
import
PitchDNN
from
wexchange.torch
import
dump_torch_weights
from
wexchange.c_export
import
CWriter
,
print_vector
...
...
@@ -52,39 +52,51 @@ def c_export(args, model):
message
=
f
"
Auto generated from checkpoint
{
os
.
path
.
basename
(
args
.
checkpoint
)
}
"
enc_
writer
=
CWriter
(
os
.
path
.
join
(
args
.
output_dir
,
"
neural_pitch_data
"
),
message
=
message
,
model_struct_name
=
'
nnp
itch
'
)
enc_
writer
.
header
.
write
(
writer
=
CWriter
(
os
.
path
.
join
(
args
.
output_dir
,
"
neural_pitch_data
"
),
message
=
message
,
model_struct_name
=
'
P
itch
DNN
'
)
writer
.
header
.
write
(
f
"""
#include
"
opus_types.h
"
"""
)
# encoder
encoder_dense_layers
=
[
(
'
initial
'
,
'
initial
'
,
'
TANH
'
),
(
'
upsample
'
,
'
upsample
'
,
'
TANH
'
)
layers
=
[
(
'
if_upsample.0
'
,
"
dense_if_upsampler_1
"
),
(
'
if_upsample.2
'
,
"
dense_if_upsampler_2
"
),
(
'
conv.1
'
,
"
conv2d_1
"
),
(
'
conv.4
'
,
"
conv2d_2
"
),
(
'
conv.7
'
,
"
conv2d_3
"
),
(
'
downsample.0
'
,
"
dense_downsampler
"
),
(
"
upsample.0
"
,
"
dense_final_upsampler
"
)
]
for
name
,
export_name
,
_
in
encoder_dense_layers
:
for
name
,
export_name
in
layers
:
layer
=
model
.
get_submodule
(
name
)
dump_torch_weights
(
enc_
writer
,
layer
,
name
=
export_name
,
verbose
=
True
)
dump_torch_weights
(
writer
,
layer
,
name
=
export_name
,
verbose
=
True
)
encoder_
gru_layers
=
[
(
'
gru
'
,
'
gru
'
,
'
TANH
'
),
gru_layers
=
[
(
"
GRU
"
,
"
gru
_1
"
),
]
enc_max_rnn_units
=
max
([
dump_torch_weights
(
enc_writer
,
model
.
get_submodule
(
name
),
export_name
,
verbose
=
True
,
input_sparse
=
False
,
quantize
=
False
)
for
name
,
export_name
,
_
in
encoder_gru_layers
])
max_rnn_units
=
max
([
dump_torch_weights
(
writer
,
model
.
get_submodule
(
name
),
export_name
,
verbose
=
True
,
input_sparse
=
False
,
quantize
=
False
)
for
name
,
export_name
in
gru_layers
])
writer
.
header
.
write
(
f
"""
#define PITCH_DNN_MAX_RNN_UNITS
{
max_rnn_units
}
"""
)
del
enc_writer
writer
.
close
()
if
__name__
==
"
__main__
"
:
os
.
makedirs
(
args
.
output_dir
,
exist_ok
=
True
)
model
=
large_if_ccode
()
checkpoint
=
torch
.
load
(
args
.
checkpoint
,
map_location
=
'
cpu
'
)
model
=
PitchDNN
()
checkpoint
=
torch
.
load
(
args
.
checkpoint
,
map_location
=
'
cpu
'
)
model
.
load_state_dict
(
checkpoint
[
'
state_dict
'
])
c_export
(
args
,
model
)
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