m-lyon / face-comparison

AI Face comparison using FaceNet
MIT License
77 stars 23 forks source link

No module named 'keras.backend.tensorflow_backend'; 'keras.backend' is not a package #2

Open woodserino opened 4 years ago

woodserino commented 4 years ago

I'm getting the following error:

ModuleNotFoundError: No module named 'keras.backend.tensorflow_backend'; 'keras.backend' is not a package

when I try to run facecompare. So far I've tried changing keras and TF versions (as per https://stackoverflow.com/questions/58047454/how-to-fix-module-keras-backend-tensorflow-backend-has-no-attribute-is-tf) but I haven't found a solution that works yet.

Using tensorflow 2.3.0, keras 2.4.3 and python 3.8.5

devDebajo commented 4 years ago

I have the same problem. How to solve it?

m-lyon commented 4 years ago

This error is caused due to the fact that TensorFlow/Keras have changed their APIs slightly since initially releasing this module.

I've removed/changed the offending lines of code, and fixed the specific versions of TensorFlow and Keras used, so this should now resolve the issue.

Please let me know if this has resolved the issue for you. To update to the latest release: pip install --upgrade face-compare

devDebajo commented 4 years ago

Thanks for reactive solving problem. I'll try new version later today

devDebajo commented 4 years ago

This issue fixed But I got new problem: _tensorflow.python.framework.errorsimpl.InvalidArgumentError: Default MaxPoolingOp only supports NHWC on device type CPU

I have installed intel-tensorflow, but it have no any effect

My configuration: Windows 10 Intel Core i5-6500 Nvidia GTX 1060 6GB (without installed CUDA)

m-lyon commented 4 years ago

This issue fixed But I got new problem: _tensorflow.python.framework.errorsimpl.InvalidArgumentError: Default MaxPoolingOp only supports NHWC on device type CPU

Yes, I encountered this problem too. NHWC refers to the order in which the data is stored so Number x Height x Width x Channels. As it turns out this model is trained on data that is in NCHW format or Number x Channels x Height x Width. The reason you get the error is that NCHW is not natively supported for the CPU implementation of TensorFlow. I believe that if you had CUDA configured that this wouldn't be an issue.

This problem can be fixed however by installing the Intel optimization for TensorFlow via pip install intel-tensorflow

More information for which can be found here. I've also added this as a known issue to the README.md page.

Hope this helps.

devDebajo commented 4 years ago

Yes, I have installed intel-tensorflow, but error remained

m-lyon commented 4 years ago

Hmm, my only suggestion would be to see if any of the other installation options on the intel optimization for tensorflow page work.

Using the intel-tensorflow in Windows 10 Ubuntu Subshell worked for me.

Since you have an NVIDIA graphics card, is installing CUDA an option for you?

Sailkiki commented 2 years ago

I can help you, the TF2 has already delete the module of set_session, i give your a example

this is wrong from keras import backend as K tf_session = tf.compat.v1.Session(graph=tf.compat.v1.get_default_graph(),config=config) K.set_session(tf_session)

and the complie shew that AttributeError: module 'keras.backend' has no attribute 'set_session'

you can fix it by follows tf_session = tf.compat.v1.Session(graph=tf.compat.v1.get_default_graph(),config=config) tf.compat.v1.keras.backend.set_session(tf_session)

ramesh-mahesh commented 1 year ago

Hello Team,

Please help me in resolving the issue.

Python: 3.10.6 Pip: 22.0.2 Tensorflow: 2.11.0 Keras: 2.11.0

Error: Traceback (most recent call last): File "/usr/local/bin/compare_faces.py", line 8, in from face_compare.model import facenet_model, img_to_encoding File "/usr/local/lib/python3.10/dist-packages/face_compare/model.py", line 6, in import keras.backend.tensorflow_backend as tfback ModuleNotFoundError: No module named 'keras.backend.tensorflow_backend'; 'keras.backend' is not a package

FurkanGozukara commented 1 year ago

tf_session

where is this file we need to check? i have this problem

https://github.com/m-lyon/face-comparison/issues/5#issuecomment-1526143778

FurkanGozukara commented 1 year ago

Hmm, my only suggestion would be to see if any of the other installation options on the intel optimization for tensorflow page work.

Using the intel-tensorflow in Windows 10 Ubuntu Subshell worked for me.

Since you have an NVIDIA graphics card, is installing CUDA an option for you?

i have nvidia and CUDA installed still not working

m-lyon commented 1 year ago

Are you sure CUDA is enabled and visible to tensorflow? you can check via tf.config.list_physical_devices('GPU')