Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chapter 5. model save problem. #6

Open
zoldaten opened this issue Mar 13, 2024 · 1 comment
Open

chapter 5. model save problem. #6

zoldaten opened this issue Mar 13, 2024 · 1 comment

Comments

@zoldaten
Copy link

i worked with jupyter notebook using tensorflow-2.16.1 and got stuck with model save.
found out that tensorflow uses keras 3.0.
i fixed the problem with https://keras.io/guides/migrating_to_keras_3/ but could not quantize model.
have to downgrade tensorflow to 2.8.0 as it uses keras 2.0.

Moreover i got a quite huge model 3.6Мб !
dont know whats wrong with it as tflite model is less 1Мб (see attached) ?
*i didnot make photoes of bathrooms just took cats, dogs and horses as classes.

models.zip

@zoldaten
Copy link
Author

ok. got it fixed.
as i using windows i have to convert tfmodel to C array with this code:

import numpy as np
import os

def convert_tflite_to_header(tflite_path, output_header_path):

    with open(tflite_path, 'rb') as tflite_file:
        tflite_content = tflite_file.read()


    hex_lines = [', '.join([f'0x{byte:02x}' for byte in tflite_content[i:i+12]]) for i in range(0, len(tflite_content), 12)]


    hex_array = ',\n  '.join(hex_lines)


    with open(output_header_path, 'w') as header_file:
        
        header_file.write('const unsigned char model[] = {\n  ')
        header_file.write(f'{hex_array}\n')
        header_file.write('};\n\n')
    
if __name__ == "__main__":
    tflite_path = 'model.tflite'
    output_header_path = 'model.h'

    convert_tflite_to_header(tflite_path, output_header_path)
    convert_tflite_to_header(tflite_path, output_header_path)

compare with xxd -c 60 -i model.tflite > indoor_scene_recognition.h on linux !

after that i couldnt catch why i cant compile.
the problem was with tflu_model = tflite::GetModel(model); where model name should be taken from model.h:
const unsigned char model[] = { - i.e. model

moreover i have to include debug_log.cpp from tflibrary hello_world.
and lib i useed Arduino_TensorFlowLite-2.4.0-ALPHA-precompiled not from this Book.

files.zip

so... it works!
2024-03-14_14h57_23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant