Skip to content

Commit

Permalink
Code Update 2
Browse files Browse the repository at this point in the history
  • Loading branch information
solasolo committed May 26, 2022
1 parent 59fb49b commit 00fa0a0
Show file tree
Hide file tree
Showing 6 changed files with 8,332 additions and 7,912 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__pycache__
.ipynb_checkpoints
.vscode
*.csv
*.csv
*.bak
15,768 changes: 7,884 additions & 7,884 deletions Host/model.h

Large diffs are not rendered by default.

453 changes: 436 additions & 17 deletions Host/tinyml.ipynb

Large diffs are not rendered by default.

14 changes: 7 additions & 7 deletions Host/tinyml.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def CreateModel():
model.add(layers.Dense(2, activation='softmax'))

opt_adam = keras.optimizers.Adam()
model.compile(optimizer=opt_adam, loss='sparse_categorical_crossentropy', metrics=['sparse_categorical_accuracy'])
model.compile(optimizer=opt_adam, loss='categorical_crossentropy', metrics=['categorical_accuracy'])
model.summary()

return model
Expand Down Expand Up @@ -72,10 +72,10 @@ def Hex2H(model, h_model_name):
c_str += '#define ' + h_model_name.upper() + '_H\n'

# Add array length at top of file
c_str += '\nunsigned int ' + h_model_name + '_len = ' + str(model_len) + ';\n'
c_str += '\nconst unsigned int ' + h_model_name + '_len = ' + str(model_len) + ';\n'

# Declare C variable
c_str += 'unsigned char ' + h_model_name + '[] = {'
c_str += 'const unsigned char ' + h_model_name + '[] = {'
hex_array = []
for i, val in enumerate(model) :
# Construct string from hex
Expand Down Expand Up @@ -105,8 +105,8 @@ def ReadDataFile(file, v):
size = SAMPLES_PER_GESTURE * 6

dataX = np.empty([0, size])
dataY = np.empty([0,])
# dataY = np.empty([0, 2])
# dataY = np.empty([0,])
dataY = np.empty([0, 2])

base_path = os.path.dirname(__file__)
file = open(base_path + "/data/" + file, "r")
Expand All @@ -125,8 +125,8 @@ def ReadDataFile(file, v):
tmp = np.expand_dims(tmp, axis=0)

dataX = np.concatenate((dataX, tmp), axis=0)
dataY = np.append(dataY, v)
#dataY = np.concatenate((dataY, [[0, 1]] if v == 0 else [[1, 0]]))
# dataY = np.append(dataY, v)
dataY = np.concatenate((dataY, [[1, 0]] if v == 0 else [[0, 1]]))

return dataX, dataY

Expand Down
4 changes: 2 additions & 2 deletions predict_gesture/model.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef MODEL_H
#define MODEL_H

unsigned int model_len = 96572;
unsigned char model[] = {
const unsigned int model_len = 96572;
const unsigned char model[] = {
0x1c, 0x00, 0x00, 0x00, 0x54, 0x46, 0x4c, 0x33, 0x14, 0x00, 0x20, 0x00,
0x1c, 0x00, 0x18, 0x00, 0x14, 0x00, 0x10, 0x00, 0x0c, 0x00, 0x00, 0x00,
0x08, 0x00, 0x04, 0x00, 0x14, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00,
Expand Down
2 changes: 1 addition & 1 deletion predict_gesture/predict_gesture.ino
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ bool Inference()

void Result()
{
float p_threshold = 0.999;
float p_threshold = 0.99;

auto p_cross = tflOutputTensor->data.f[0];
auto p_circle = tflOutputTensor->data.f[1];
Expand Down

0 comments on commit 00fa0a0

Please sign in to comment.