Closed expeon07 closed 2 years ago
Hi @expeon07 ,
If I understand the Keras summary correctly you have the following network: 50-10(relu)-10(relu)-5(relu)
This will be too large for the Uno. I built you a quick example for the Mega (Wokwi simulation): https://wokwi.com/projects/329367430475285076
I use the FlatWeight method here. So all weights in a row in one array. With so many weights it is much safer. Here is the link to the tutorial: https://create.arduino.cc/projecthub/aifes_team/aifes-inference-tutorial-f44d96
You have to put your weights in the "weights.h". I have only stored an array with ones here.
We will soon provide Python wrappers to export a model with one code line. Here is a code snippet how to extract the weights directly in the right order from your Keras model.
First the weight sort function:
import collections
# Convert the weights to AIfES FlatWeights
def flatten_weights(weights):
w = []
for l in weights:
if isinstance(l, collections.Iterable):
w = w + flatten_weights(l)
else:
w = w + [l]
return w
And this is how you use it in Keras:
# Get weights
weights = model.get_weights()
aifes_flat_weights = flatten_weights(weights)
print("\n\n")
print("const float FlatWeights[] = {")
n = m = 0
while m < len(aifes_flat_weights):
m = m + 5
weight_line = 'f, '.join(map(str, aifes_flat_weights[n:m]))
if m < len(aifes_flat_weights):
weight_line = weight_line + "f,"
else:
weight_line = weight_line + "};\n\n"
print(weight_line)
n = m
Let us know if it worked 😀
Hi, thanks a lot! I reduced the model and it fits the Uno now. I also spent some time trying to figure out how to use PROGMEM with my weights and biases into the model but I finally got it working by separating the arrays in another header file, as you mentioned.
I think a wrapper in python to export the model would be great!
Hi @expeon07
great news. Awesome that it worked out. 👍
I don't know what your network is doing, but if you do a Hackster or Arduino Project, let me know.😀
Hi @AIfES-Pierre, I'm using your framework for my thesis. I'll let you know when it's finished :D
Hi! I have a sequential model from Keras and I'm trying to deploy it to Arduino Uno using AIfES.
This is my model in Keras:
However, my outputs are 0. Can you check if my configuration in Arduino is correct?
Thank you!!!