Skip to content

Commit

Permalink
Make RDOVAE encoder use LinearLayer directly
Browse files Browse the repository at this point in the history
  • Loading branch information
jmvalin committed Jul 28, 2023
1 parent eb72d29 commit ad05730
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 24 deletions.
4 changes: 1 addition & 3 deletions autogen.bat
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ for /F "tokens=4 delims= " %%A in ('findstr "download_model.sh" autogen.sh') do
REM Remove trailing ")" character from the model variable
set "model=%model:~0,-1%"

cd dnn
call download_model.bat %model%
cd ..
call dnn\download_model.bat %model%

echo Updating build configuration files, please wait....
2 changes: 1 addition & 1 deletion autogen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ set -e
srcdir=`dirname $0`
test -n "$srcdir" && cd "$srcdir"

(cd dnn; ./download_model.sh 2ddc476)
dnn/download_model.sh eb72d29

echo "Updating build configuration files, please wait...."

Expand Down
2 changes: 0 additions & 2 deletions dnn/download_model.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,3 @@ if not exist %model% (
)

tar -xvzf %model%
move .\src\*.c .
move .\src\*.h .
4 changes: 1 addition & 3 deletions dnn/download_model.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ if [ ! -f $model ]; then
wget https://media.xiph.org/lpcnet/data/$model
fi
tar xvof $model
touch src/nnet_data.[ch]
touch src/plc_data.[ch]
mv src/*.[ch] .
touch *_data.[ch]
23 changes: 11 additions & 12 deletions dnn/dred_rdovae_enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,50 +46,49 @@ void dred_rdovae_encode_dframe(
float buffer[ENC_DENSE1_OUT_SIZE + ENC_DENSE2_OUT_SIZE + ENC_DENSE3_OUT_SIZE + ENC_DENSE4_OUT_SIZE + ENC_DENSE5_OUT_SIZE + ENC_DENSE6_OUT_SIZE + ENC_DENSE7_OUT_SIZE + ENC_DENSE8_OUT_SIZE + GDENSE1_OUT_SIZE];
int output_index = 0;
int input_index = 0;
float zero_vector[1024] = {0};

/* run encoder stack and concatenate output in buffer*/
_lpcnet_compute_dense(&model->enc_dense1, &buffer[output_index], input);
compute_generic_dense(&model->enc_dense1, &buffer[output_index], input, ACTIVATION_TANH);
input_index = output_index;
output_index += ENC_DENSE1_OUT_SIZE;

compute_gruB(&model->enc_dense2, zero_vector, enc_state->dense2_state, &buffer[input_index]);
compute_generic_gru(&model->enc_dense2_input, &model->enc_dense2_recurrent, enc_state->dense2_state, &buffer[input_index]);
OPUS_COPY(&buffer[output_index], enc_state->dense2_state, ENC_DENSE2_OUT_SIZE);
input_index = output_index;
output_index += ENC_DENSE2_OUT_SIZE;

_lpcnet_compute_dense(&model->enc_dense3, &buffer[output_index], &buffer[input_index]);
compute_generic_dense(&model->enc_dense3, &buffer[output_index], &buffer[input_index], ACTIVATION_TANH);
input_index = output_index;
output_index += ENC_DENSE3_OUT_SIZE;

compute_gruB(&model->enc_dense4, zero_vector, enc_state->dense4_state, &buffer[input_index]);
compute_generic_gru(&model->enc_dense4_input, &model->enc_dense4_recurrent, enc_state->dense4_state, &buffer[input_index]);
OPUS_COPY(&buffer[output_index], enc_state->dense4_state, ENC_DENSE4_OUT_SIZE);
input_index = output_index;
output_index += ENC_DENSE4_OUT_SIZE;

_lpcnet_compute_dense(&model->enc_dense5, &buffer[output_index], &buffer[input_index]);
compute_generic_dense(&model->enc_dense5, &buffer[output_index], &buffer[input_index], ACTIVATION_TANH);
input_index = output_index;
output_index += ENC_DENSE5_OUT_SIZE;

compute_gruB(&model->enc_dense6, zero_vector, enc_state->dense6_state, &buffer[input_index]);
compute_generic_gru(&model->enc_dense6_input, &model->enc_dense6_recurrent, enc_state->dense6_state, &buffer[input_index]);
OPUS_COPY(&buffer[output_index], enc_state->dense6_state, ENC_DENSE6_OUT_SIZE);
input_index = output_index;
output_index += ENC_DENSE6_OUT_SIZE;

_lpcnet_compute_dense(&model->enc_dense7, &buffer[output_index], &buffer[input_index]);
compute_generic_dense(&model->enc_dense7, &buffer[output_index], &buffer[input_index], ACTIVATION_TANH);
input_index = output_index;
output_index += ENC_DENSE7_OUT_SIZE;

_lpcnet_compute_dense(&model->enc_dense8, &buffer[output_index], &buffer[input_index]);
compute_generic_dense(&model->enc_dense8, &buffer[output_index], &buffer[input_index], ACTIVATION_TANH);
output_index += ENC_DENSE8_OUT_SIZE;

/* compute latents from concatenated input buffer */
compute_conv1d(&model->bits_dense, latents, enc_state->bits_dense_state, buffer);
compute_generic_conv1d(&model->bits_dense, latents, enc_state->bits_dense_state, buffer, BITS_DENSE_IN_SIZE, ACTIVATION_LINEAR);


/* next, calculate initial state */
_lpcnet_compute_dense(&model->gdense1, &buffer[output_index], buffer);
compute_generic_dense(&model->gdense1, &buffer[output_index], buffer, ACTIVATION_TANH);
input_index = output_index;
_lpcnet_compute_dense(&model->gdense2, initial_state, &buffer[input_index]);
compute_generic_dense(&model->gdense2, initial_state, &buffer[input_index], ACTIVATION_TANH);

}
2 changes: 1 addition & 1 deletion dnn/nnet.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ int sample_from_pdf(const float *pdf, int N, float exp_boost, float pdf_floor);

extern const WeightArray lpcnet_arrays[];
extern const WeightArray lpcnet_plc_arrays[];
extern const WeightArray rdovae_enc_arrays[];
extern const WeightArray rdovaeenc_arrays[];
extern const WeightArray rdovae_dec_arrays[];

int linear_init(LinearLayer *layer, const WeightArray *arrays,
Expand Down
2 changes: 1 addition & 1 deletion dnn/write_lpcnet_weights.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int main(void)
FILE *fout = fopen("weights_blob.bin", "w");
write_weights(lpcnet_arrays, fout);
write_weights(lpcnet_plc_arrays, fout);
write_weights(rdovae_enc_arrays, fout);
write_weights(rdovaeenc_arrays, fout);
write_weights(rdovae_dec_arrays, fout);
fclose(fout);
return 0;
Expand Down
2 changes: 1 addition & 1 deletion silk/dred_encoder.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void dred_encoder_init(DREDEnc* enc, opus_int32 Fs, int channels)
enc->Fs = Fs;
enc->channels = channels;
#ifndef USE_WEIGHTS_FILE
init_rdovaeenc(&enc->model, rdovae_enc_arrays);
init_rdovaeenc(&enc->model, rdovaeenc_arrays);
#endif
dred_encoder_reset(enc);
}
Expand Down

0 comments on commit ad05730

Please sign in to comment.