av-savchenko / face-emotion-recognition

Efficient face emotion recognition in photos and videos
Apache License 2.0
692 stars 127 forks source link

Getting error when converting emotions mobilenet model to tensorflow lite #52

Closed quanlt2 closed 1 month ago

quanlt2 commented 1 month ago

Hello, First thank you for your work on this repo. I got an error when running file to_tflite.py in mobile_app folder on my Mac. Here is steps which I did:

  1. clone the repo
  2. create env by virtualenv (python3.9)
  3. install tensorflow: python3 -m pip install tensorflow
  4. cd mobile_app
  5. python3 to_tflite.py

I got the error log: (env) Quans-Mac mobile_app % python3 to_tflite.py 2024-09-26 10:08:17.568254: I tensorflow/core/platform/cpu_feature_guard.cc:210] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations. To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags. /Volumes/BACKVIET/work/workspace/AndroidStudio/face-emotion/env/lib/python3.9/site-packages/urllib3/init.py:35: NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 2.8.3'. See: https://github.com/urllib3/urllib3/issues/3020 warnings.warn( app/src/main/assets/emotions_mobilenet Traceback (most recent call last): File "/Volumes/BACKVIET/work/workspace/AndroidStudio/face-emotion/mobile_app/to_tflite.py", line 41, in convert_h5('../models/affectnet_emotions/mobilenet_7.h5', 'app/src/main/assets/emotions_mobilenet',quantize=False) File "/Volumes/BACKVIET/work/workspace/AndroidStudio/face-emotion/mobile_app/to_tflite.py", line 31, in convert_h5 converter = tf.compat.v1.lite.TFLiteConverter.from_keras_model_file( input_model_file) File "/Volumes/BACKVIET/work/workspace/AndroidStudio/face-emotion/env/lib/python3.9/site-packages/tensorflow/lite/python/lite.py", line 3220, in from_keras_model_file return TFLiteKerasModelConverter( File "/Volumes/BACKVIET/work/workspace/AndroidStudio/face-emotion/env/lib/python3.9/site-packages/tensorflow/lite/python/lite.py", line 2675, in init keras_model = keras_deps.get_load_model_function()( TypeError: 'NoneType' object is not callable

Any idea for fix? Thank you

av-savchenko commented 1 month ago

It seems that this issue is caused by some new inconsistencies with latest version of Tensowrlow and Keras. I did not install them but I simply found an advice in the Tensorflow issue to use the following code:

!pip install -U tf_keras # Keras 2
import os
os.environ["TF_USE_LEGACY_KERAS"] = "1"
quanlt2 commented 1 month ago

I downgrade the TensorFlow version from 2.16.2 to 2.13.1 yesterday and it works like charms. Perhaps the reason as you tell above, so i think you the code should be migrated soon to new version of TensorFlow Thank you for your great work on this repo