Unverified Commit da83a5bb authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

toplevel function

parent 1399bd86
......@@ -158,12 +158,29 @@ void compute_gru(const GRULayer *gru, float *state, const float *input)
#if 1
#define INPUT_SIZE 42
int main() {
float vad_out[MAX_NEURONS] = {0};
float input[INPUT_SIZE];
void compute_rnn(RNNState *rnn, float *gains, float *vad, const float *input) {
int i;
float dense_out[MAX_NEURONS];
float noise_input[MAX_NEURONS*3];
float denoise_input[MAX_NEURONS*3];
compute_dense(&input_dense, dense_out, input);
compute_gru(&vad_gru, rnn->vad_gru_state, dense_out);
compute_dense(&vad_output, vad, rnn->vad_gru_state);
for (i=0;i<INPUT_DENSE_SIZE;i++) noise_input[i] = dense_out[i];
for (i=0;i<VAD_GRU_SIZE;i++) noise_input[i+INPUT_DENSE_SIZE] = rnn->vad_gru_state[i];
for (i=0;i<INPUT_SIZE;i++) noise_input[i+INPUT_DENSE_SIZE+VAD_GRU_SIZE] = input[i];
compute_gru(&noise_gru, rnn->noise_gru_state, noise_input);
for (i=0;i<VAD_GRU_SIZE;i++) denoise_input[i] = rnn->vad_gru_state[i];
for (i=0;i<NOISE_GRU_SIZE;i++) denoise_input[i+VAD_GRU_SIZE] = rnn->noise_gru_state[i];
for (i=0;i<INPUT_SIZE;i++) denoise_input[i+VAD_GRU_SIZE+NOISE_GRU_SIZE] = input[i];
compute_gru(&denoise_gru, rnn->denoise_gru_state, denoise_input);
compute_dense(&denoise_output, gains, rnn->denoise_gru_state);
}
int main() {
float vad_out[MAX_NEURONS] = {0};
float input[INPUT_SIZE];
float gains[DENOISE_OUTPUT_SIZE];
RNNState rnn;
RNN_CLEAR(&rnn, 1);
......@@ -173,24 +190,9 @@ int main() {
for (i=0;i<INPUT_SIZE;i++) scanf("%f", &input[i]);
for (i=0;i<45;i++) scanf("%f", &vad_out[0]);
if (feof(stdin)) break;
compute_dense(&input_dense, dense_out, input);
compute_gru(&vad_gru, rnn.vad_gru_state, dense_out);
compute_dense(&vad_output, vad_out, rnn.vad_gru_state);
#if 1
for (i=0;i<INPUT_DENSE_SIZE;i++) noise_input[i] = dense_out[i];
for (i=0;i<VAD_GRU_SIZE;i++) noise_input[i+INPUT_DENSE_SIZE] = rnn.vad_gru_state[i];
for (i=0;i<INPUT_SIZE;i++) noise_input[i+INPUT_DENSE_SIZE+VAD_GRU_SIZE] = input[i];
compute_gru(&noise_gru, rnn.noise_gru_state, noise_input);
for (i=0;i<VAD_GRU_SIZE;i++) denoise_input[i] = rnn.vad_gru_state[i];
for (i=0;i<NOISE_GRU_SIZE;i++) denoise_input[i+VAD_GRU_SIZE] = rnn.noise_gru_state[i];
for (i=0;i<INPUT_SIZE;i++) denoise_input[i+VAD_GRU_SIZE+NOISE_GRU_SIZE] = input[i];
compute_gru(&denoise_gru, rnn.denoise_gru_state, denoise_input);
compute_dense(&denoise_output, gains, rnn.denoise_gru_state);
compute_rnn(&rnn, gains, vad_out, input);
for (i=0;i<22;i++) printf("%f ", gains[i]);
#endif
printf("%f\n", vad_out[0]);
}
}
......
......@@ -54,8 +54,12 @@ typedef struct {
int activation;
} GRULayer;
typedef struct RNNState RNNState;
void compute_dense(const DenseLayer *layer, float *output, const float *input);
void compute_gru(const GRULayer *gru, float *state, const float *input);
void compute_rnn(RNNState *rnn, float *gains, float *vad, const float *input);
#endif /* _MLP_H_ */
......@@ -74,10 +74,10 @@ for i, layer in enumerate(model.layers):
if len(layer.get_weights()) > 2:
layer_list.append(layer.name)
hf.write('typedef struct {\n')
hf.write('struct RNNState {\n')
for i, name in enumerate(layer_list):
hf.write(' float {}_state[{}_SIZE];\n'.format(name, name.upper()))
hf.write('} RNNState;\n')
hf.write('};\n')
hf.write('\n\n#endif\n')
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment