eloquentarduino / EloquentTinyML

Eloquent interface to Tensorflow Lite for Microcontrollers
284 stars 56 forks source link

digits_model.py #15

Closed rkuo2000 closed 3 years ago

rkuo2000 commented 3 years ago

I found the fix.

When running tinymlgen, optimize default is True, the generated model file is quite small and cause ESP32 keep aborting.

After I modify digits_model.py to set optimize = False, like below : c_code = port(model, variable_name='digits_model', pretty_print=True, optimize=False) with open('digits_model.h', 'w') as f: print(c_code, file=f)

My Arduino example TinyML_Digit are running on ESP32 now !

rkuo2000 commented 3 years ago

After set Optimize=False to convert the model to ccode, I can also run 28x28 MNIST on ESP32 now Here's my Arduino example TinyML_MNIST for your reference.

eloquentarduino commented 3 years ago

Where did you find optimize=True in my tutorials? I already switched to optimize=False in the latest version of tinymlgen.

rkuo2000 commented 3 years ago

https://eloquentarduino.github.io/2020/01/easy-tinyml-on-esp32-and-arduino/ converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE] <-- this indicates it needs OPTIMIZED_FOR_SIZE

and

c_code = port(model, pretty_print=True) <-- also in your digits_model.py print(c_code)

The above code did not specify optimize=False, and it will generate a very small code. (my tinymlgen is v0.2 which is the current version)

eloquentarduino commented 3 years ago

Thanks, I removed converter.optimizations = [tf.lite.Optimize.OPTIMIZE_FOR_SIZE] from the post. tinymlgen version 0.3 switched to optimize=False by default

rkuo2000 commented 3 years ago

Thanks for your great work !

whubaichuan commented 2 years ago

@eloquentarduino It seems that in 2.4.3 (the latest version currently on 2022.09.02),

c_code = port(model, pretty_print=True) <-- also in your digits_model.py
print(c_code)

does not specify optimize=False, and it will generate a very small code.

eloquentarduino commented 2 years ago

Optimization seems to break the exported code. For the moment I will default to optimize=False