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

Conditional import of Keras/TFLite in model.py #6

Closed
fegue opened this issue Mar 28, 2022 · 4 comments
Closed

Conditional import of Keras/TFLite in model.py #6

fegue opened this issue Mar 28, 2022 · 4 comments

Comments

@fegue
Copy link
Collaborator

fegue commented Mar 28, 2022

When running BirdNET on a Raspberry Pi it is sufficient to install tflite-runtime without the need to install tensorflow.
Not having to install tensorflow/keras keeps the installation smaller and the process simpler.

It would be great if the import could be conditional so that the script does not throw an error when there is no installation of tensorflow.

It could be something like

if cfg.MODEL_PATH.endswith('.tflite'):
    try:
        import tflite_runtime.interpreter as tflite
    except ModuleNotFoundError:
        from tensorflow import lite as tflite
else:
   from tensorflow import keras
@kahst
Copy link
Owner

kahst commented Mar 28, 2022

Just pushed the conditional import, can you give it a go and see if it works? Seems to work fine on my machine, yet, I'm not using the TFLite runtime. I'll update the documentation accordingly.

@mcguirepr89
Copy link
Contributor

mcguirepr89 commented Mar 28, 2022

The TFLite runtime is working great for me -- thanks!

@kahst
Copy link
Owner

kahst commented Mar 29, 2022

I realized that TFLite-runtime 2.5.0 won't work, it has to be 2.7.0. Yet, this version doesn't seem to be available for all Python distros, e.g. the one I use on Windows. Therefore, I only recommend installing it on Ubuntu in the setup tutorial. Still closing this issue since it seems to work aside from that.

@kahst kahst closed this as completed Mar 29, 2022
@fegue
Copy link
Collaborator Author

fegue commented Mar 29, 2022

I'll test it as soon as I have a RPi near me.
I have only run the code with tflite-runtime 2.7.0 which is available on Raspbian Bullseye

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

No branches or pull requests

3 participants