ref: a223122b8946c7929081de33d8dada66646b35aa
parent: 585de8e4671f8994b80451c36268dd1c7dd51269
author: Jan Buethe <jbuethe@amazon.de>
date: Wed Oct 26 08:42:34 EDT 2022
clean-up
--- a/dnn/dred_rdovae_dec.c
+++ b/dnn/dred_rdovae_dec.c
@@ -32,11 +32,7 @@
#include "dred_rdovae_dec.h"
#include "dred_rdovae_constants.h"
-//#define DEBUG
-#ifdef DEBUG
-#include <stdio.h>
-#endif
void dred_rdovae_dec_init_states(
RDOVAEDec *h, /* io: state buffer handle */
@@ -59,78 +55,40 @@
float buffer[DEC_DENSE1_OUT_SIZE + DEC_DENSE2_OUT_SIZE + DEC_DENSE3_OUT_SIZE + DEC_DENSE4_OUT_SIZE + DEC_DENSE5_OUT_SIZE + DEC_DENSE6_OUT_SIZE + DEC_DENSE7_OUT_SIZE + DEC_DENSE8_OUT_SIZE];
int output_index = 0;
int input_index = 0;
-#ifdef DEBUG
- static FILE *fids[8] = {NULL};
- int i;
- char filename[256];
- for (i=0; i < 8; i ++)
- {
- if (fids[i] == NULL)
- {
- sprintf(filename, "y%d.f32", i + 1);
- fids[i] = fopen(filename, "wb");
- }
- }
-#endif
-
/* run encoder stack and concatenate output in buffer*/
_lpcnet_compute_dense(&dec_dense1, &buffer[output_index], input);
-#ifdef DEBUG
- fwrite(&buffer[output_index], sizeof(buffer[0]), DEC_DENSE1_OUT_SIZE, fids[0]);
-#endif
input_index = output_index;
output_index += DEC_DENSE1_OUT_SIZE;
compute_gru2(&dec_dense2, dec_state->dense2_state, &buffer[input_index]);
memcpy(&buffer[output_index], dec_state->dense2_state, DEC_DENSE2_OUT_SIZE * sizeof(float));
-#ifdef DEBUG
- fwrite(&buffer[output_index], sizeof(buffer[0]), DEC_DENSE2_OUT_SIZE, fids[1]);
-#endif
input_index = output_index;
output_index += DEC_DENSE2_OUT_SIZE;
_lpcnet_compute_dense(&dec_dense3, &buffer[output_index], &buffer[input_index]);
-#ifdef DEBUG
- fwrite(&buffer[output_index], sizeof(buffer[0]), DEC_DENSE3_OUT_SIZE, fids[2]);
-#endif
input_index = output_index;
output_index += DEC_DENSE3_OUT_SIZE;
compute_gru2(&dec_dense4, dec_state->dense4_state, &buffer[input_index]);
memcpy(&buffer[output_index], dec_state->dense4_state, DEC_DENSE4_OUT_SIZE * sizeof(float));
-#ifdef DEBUG
- fwrite(&buffer[output_index], sizeof(buffer[0]), DEC_DENSE4_OUT_SIZE, fids[3]);
-#endif
input_index = output_index;
output_index += DEC_DENSE4_OUT_SIZE;
_lpcnet_compute_dense(&dec_dense5, &buffer[output_index], &buffer[input_index]);
-#ifdef DEBUG
- fwrite(&buffer[output_index], sizeof(buffer[0]), DEC_DENSE5_OUT_SIZE, fids[4]);
-#endif
input_index = output_index;
output_index += DEC_DENSE5_OUT_SIZE;
compute_gru2(&dec_dense6, dec_state->dense6_state, &buffer[input_index]);
memcpy(&buffer[output_index], dec_state->dense6_state, DEC_DENSE6_OUT_SIZE * sizeof(float));
-#ifdef DEBUG
- fwrite(&buffer[output_index], sizeof(buffer[0]), DEC_DENSE6_OUT_SIZE, fids[5]);
-#endif
input_index = output_index;
output_index += DEC_DENSE6_OUT_SIZE;
_lpcnet_compute_dense(&dec_dense7, &buffer[output_index], &buffer[input_index]);
-#ifdef DEBUG
- fwrite(&buffer[output_index], sizeof(buffer[0]), DEC_DENSE7_OUT_SIZE, fids[6]);
-#endif
input_index = output_index;
output_index += DEC_DENSE7_OUT_SIZE;
_lpcnet_compute_dense(&dec_dense8, &buffer[output_index], &buffer[input_index]);
-#ifdef DEBUG
- fwrite(&buffer[output_index], sizeof(buffer[0]), DEC_DENSE8_OUT_SIZE, fids[7]);
-#endif
output_index += DEC_DENSE8_OUT_SIZE;
_lpcnet_compute_dense(&dec_final, qframe, buffer);
--- a/dnn/dred_rdovae_dec_demo.c
+++ /dev/null
@@ -1,66 +1,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "dred_rdovae_dec.h"
-
-
-void usage()
-{
- printf("dred_rdovae_dec_demo <input> <output>\n");
- exit(1);
-}
-
-int main(int argc, char **argv)
-{
- RDOVAEDec dec_state;
- float feature_buffer[36];
- float qframe[4 * DRED_NUM_FEATURES];
- float latents[DRED_LATENT_DIM];
- float initial_state[24];
- int index = 0;
- FILE *in_fid, *out_fid;
- int qlevel = 0;
-
- memset(&dec_state, 0, sizeof(dec_state));
-
- if (argc < 3) usage();
-
- in_fid = fopen(argv[1], "rb");
- if (in_fid == NULL)
- {
- perror("Could not open input file");
- usage();
- }
-
- out_fid = fopen(argv[2], "wb");
- if (out_fid == NULL)
- {
- perror("Could not open output file");
- usage();
- }
-
- /* read initial state from input stream */
- if (fread(initial_state, sizeof(float), 24, in_fid) != 24)
- {
- perror("error while reading initial state");
- return 1;
- }
-
- /* initialize GRU states */
- dred_rdovae_dec_init_states(&dec_state, initial_state);
-
- /* start decoding */
- while (fread(latents, sizeof(float), 80, in_fid) == 80)
- {
- dred_rdovae_decode_qframe(&dec_state, qframe, latents);
- fwrite(qframe, sizeof(float), 4*20, out_fid);
- }
-
- fclose(in_fid);
- fclose(out_fid);
-
-
- return 0;
-}
-
-/* gcc -DDISABLE_DOT_PROD -DDISABLE_NEON dred_rdovae_dec_demo.c dred_rdovae_dec.c nnet.c dred_rdovae_dec_data.c dred_rdovae_stats_data.c kiss99.c -g -o dred_rdovae_dec_demo */
\ No newline at end of file
--- a/dnn/dred_rdovae_enc.c
+++ b/dnn/dred_rdovae_enc.c
@@ -35,12 +35,6 @@
#include "dred_rdovae_enc.h"
-//#define DEBUG
-
-#ifdef DEBUG
-#include <stdio.h>
-#endif
-
void dred_rdovae_encode_dframe(
RDOVAEEnc *enc_state, /* io: encoder state */
float *latents, /* o: latent vector */
@@ -51,90 +45,43 @@
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;
-#ifdef DEBUG
- static FILE *fids[8] = {NULL};
- static FILE *fpre = NULL;
- int i;
- char filename[256];
- for (i=0; i < 8; i ++)
- {
- if (fids[i] == NULL)
- {
- sprintf(filename, "x%d.f32", i + 1);
- fids[i] = fopen(filename, "wb");
- }
- }
- if (fpre == NULL)
- {
- fpre = fopen("x_pre.f32", "wb");
- }
-#endif
-
-
/* run encoder stack and concatenate output in buffer*/
_lpcnet_compute_dense(&enc_dense1, &buffer[output_index], input);
-#ifdef DEBUG
- fwrite(&buffer[output_index], sizeof(buffer[0]), ENC_DENSE1_OUT_SIZE, fids[0]);
-#endif
input_index = output_index;
output_index += ENC_DENSE1_OUT_SIZE;
compute_gru2(&enc_dense2, enc_state->dense2_state, &buffer[input_index]);
memcpy(&buffer[output_index], enc_state->dense2_state, ENC_DENSE2_OUT_SIZE * sizeof(float));
-#ifdef DEBUG
- fwrite(&buffer[output_index], sizeof(buffer[0]), ENC_DENSE2_OUT_SIZE, fids[1]);
-#endif
input_index = output_index;
output_index += ENC_DENSE2_OUT_SIZE;
_lpcnet_compute_dense(&enc_dense3, &buffer[output_index], &buffer[input_index]);
-#ifdef DEBUG
- fwrite(&buffer[output_index], sizeof(buffer[0]), ENC_DENSE3_OUT_SIZE, fids[2]);
-#endif
input_index = output_index;
output_index += ENC_DENSE3_OUT_SIZE;
compute_gru2(&enc_dense4, enc_state->dense4_state, &buffer[input_index]);
memcpy(&buffer[output_index], enc_state->dense4_state, ENC_DENSE4_OUT_SIZE * sizeof(float));
-#ifdef DEBUG
- fwrite(&buffer[output_index], sizeof(buffer[0]), ENC_DENSE4_OUT_SIZE, fids[3]);
-#endif
input_index = output_index;
output_index += ENC_DENSE4_OUT_SIZE;
_lpcnet_compute_dense(&enc_dense5, &buffer[output_index], &buffer[input_index]);
-#ifdef DEBUG
- fwrite(&buffer[output_index], sizeof(buffer[0]), ENC_DENSE5_OUT_SIZE, fids[4]);
-#endif
input_index = output_index;
output_index += ENC_DENSE5_OUT_SIZE;
compute_gru2(&enc_dense6, enc_state->dense6_state, &buffer[input_index]);
memcpy(&buffer[output_index], enc_state->dense6_state, ENC_DENSE6_OUT_SIZE * sizeof(float));
-#ifdef DEBUG
- fwrite(&buffer[output_index], sizeof(buffer[0]), ENC_DENSE6_OUT_SIZE, fids[5]);
-#endif
input_index = output_index;
output_index += ENC_DENSE6_OUT_SIZE;
_lpcnet_compute_dense(&enc_dense7, &buffer[output_index], &buffer[input_index]);
-#ifdef DEBUG
- fwrite(&buffer[output_index], sizeof(buffer[0]), ENC_DENSE7_OUT_SIZE, fids[6]);
-#endif
input_index = output_index;
output_index += ENC_DENSE7_OUT_SIZE;
_lpcnet_compute_dense(&enc_dense8, &buffer[output_index], &buffer[input_index]);
-#ifdef DEBUG
- fwrite(&buffer[output_index], sizeof(buffer[0]), ENC_DENSE8_OUT_SIZE, fids[7]);
-#endif
output_index += ENC_DENSE8_OUT_SIZE;
/* compute latents from concatenated input buffer */
-#ifdef DEBUG
- fwrite(buffer, sizeof(buffer[0]), bits_dense.nb_inputs, fpre);
-#endif
compute_conv1d(&bits_dense, latents, enc_state->bits_dense_state, buffer);
--- a/dnn/dred_rdovae_enc_demo.c
+++ /dev/null
@@ -1,72 +1,0 @@
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "dred_rdovae_enc.h"
-#include "dred_rdovae_constants.h"
-
-void usage()
-{
- printf("dred_rdovae_enc_demo <features> <latents path> <states path>\n");
- exit(1);
-}
-
-int main(int argc, char **argv)
-{
- RDOVAEEnc enc_state;
- float feature_buffer[36];
- float dframe[2 * DRED_NUM_FEATURES];
- float latents[80];
- float initial_state[24];
- int index = 0;
- FILE *fid, *latents_fid, *states_fid;
-
- memset(&enc_state, 0, sizeof(enc_state));
-
- if (argc < 4)
- {
- usage();
- }
-
- fid = fopen(argv[1], "rb");
- if (fid == NULL)
- {
- fprintf(stderr, "could not open feature file %s\n", argv[1]);
- usage();
- }
-
- latents_fid = fopen(argv[2], "wb");
- if (latents_fid == NULL)
- {
- fprintf(stderr, "could not open latents file %s\n", argv[2]);
- usage();
- }
-
- states_fid = fopen(argv[3], "wb");
- if (states_fid == NULL)
- {
- fprintf(stderr, "could not open states file %s\n", argv[3]);
- usage();
- }
-
-
- while (fread(feature_buffer, sizeof(float), 36, fid) == 36)
- {
- memcpy(&dframe[DRED_NUM_FEATURES * index++], feature_buffer, DRED_NUM_FEATURES*sizeof(float));
-
- if (index == 2)
- {
- dred_rdovae_encode_dframe(&enc_state, latents, initial_state, dframe);
- index = 0;
- fwrite(latents, sizeof(float), DRED_LATENT_DIM, latents_fid);
- fwrite(initial_state, sizeof(float), GDENSE2_OUT_SIZE, states_fid);
- }
- }
-
- fclose(fid);
- fclose(states_fid);
- fclose(latents_fid);
-
- return 0;
-}
-
-/* gcc -DDISABLE_DOT_PROD -DDISABLE_NEON dred_rdovae_enc_demo.c dred_rdovae_enc.c nnet.c dred_rdovae_enc_data.c dred_rdovae_stats_data.c kiss99.c -g -o dred_rdovae_enc_demo */
\ No newline at end of file
--
⑨