Created
October 28, 2021 19:19
-
-
Save praeclarum/6f739893e160e8bbb93a9650de802af1 to your computer and use it in GitHub Desktop.
C code implementing the neural network that I trained to control my balancing robot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "NNControl.h" | |
#include <math.h> | |
extern const float nncontrol_dense_74_weights0[320]; // (5, 64) | |
extern const float nncontrol_dense_74_weights1[64]; // (64,) | |
extern const float nncontrol_dense_75_weights0[4096]; // (64, 64) | |
extern const float nncontrol_dense_75_weights1[64]; // (64,) | |
extern const float nncontrol_dense_76_weights0[64]; // (64, 1) | |
static const float tf_math_multiply_69_Mul_0_const0[1] = {0}; | |
void nncontrol(const float *input_26, float *tf_math_multiply_69_Mul_0, nncontrol_hidden *hidden) { | |
for (int i = 0; i < 64; i++) { | |
hidden->dense_74_Relu_0[i] = nncontrol_dense_74_weights1[i]; | |
for (int j = 0; j < 5; j++) { | |
hidden->dense_74_Relu_0[i] += input_26[j]*nncontrol_dense_74_weights0[j*64 + i]; | |
} | |
} | |
for (int i = 0; i < 64; i++) { | |
if (hidden->dense_74_Relu_0[i] < 0.0f) hidden->dense_74_Relu_0[i] = 0.0f; | |
} | |
for (int i = 0; i < 64; i++) { | |
hidden->dense_75_Relu_0[i] = nncontrol_dense_75_weights1[i]; | |
for (int j = 0; j < 64; j++) { | |
hidden->dense_75_Relu_0[i] += hidden->dense_74_Relu_0[j]*nncontrol_dense_75_weights0[j*64 + i]; | |
} | |
} | |
for (int i = 0; i < 64; i++) { | |
if (hidden->dense_75_Relu_0[i] < 0.0f) hidden->dense_75_Relu_0[i] = 0.0f; | |
} | |
for (int i = 0; i < 1; i++) { | |
hidden->dense_76_Tanh_0[i] = 0.0f; | |
for (int j = 0; j < 64; j++) { | |
hidden->dense_76_Tanh_0[i] += hidden->dense_75_Relu_0[j]*nncontrol_dense_76_weights0[j*1 + i]; | |
} | |
} | |
*hidden->dense_76_Tanh_0 = tanh(*hidden->dense_76_Tanh_0); | |
*tf_math_multiply_69_Mul_0 = *hidden->dense_76_Tanh_0 * 0.3f; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment