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

api is not support tensorflow version 2.2+ #143

Closed
gavinz8 opened this issue Dec 8, 2020 · 17 comments
Closed

api is not support tensorflow version 2.2+ #143

gavinz8 opened this issue Dec 8, 2020 · 17 comments
Labels
bug Something isn't working

Comments

@gavinz8
Copy link

gavinz8 commented Dec 8, 2020

api.py not support tensorflow version 2.2.0+, when i run it, report error function get_default_graph not found, and it's can't load some models, report ValueError: rate must be a scalar tensor or a float in the range [0, 1)
image

@serengil
Copy link
Owner

serengil commented Dec 8, 2020

this is an environmental issue. unit tests were run in tf 1.9.0. you might downgrade your tf version to handle this issue.

@serengil serengil closed this as completed Dec 8, 2020
@KiLJ4EdeN
Copy link

This could easily be handled with "import tf.compat.v1 as tf", ofc needs to be applied to module level.

@serengil
Copy link
Owner

serengil commented Dec 8, 2020

@KiLJ4EdeN you mean this import should be done in deepface or out of deepface?

@serengil serengil reopened this Dec 8, 2020
@KiLJ4EdeN
Copy link

KiLJ4EdeN commented Dec 8, 2020

@KiLJ4EdeN you mean this import should be done in deepface or out of deepface?

Sadly needs to be done for the whole module (deepface) where tf 1.x stuff are imported, Might be worth trying on a separate branch though, since many install the latest tf version by default.

@serengil
Copy link
Owner

serengil commented Dec 8, 2020

it seems that downgrade is easier :)

@serengil serengil closed this as completed Dec 8, 2020
@gavinz8
Copy link
Author

gavinz8 commented Dec 9, 2020

As your told, I downgrade my version as 1.9.0, but the other dependencies must dependent tensorflow version 2.2.0+ either, tha't a bad circle dependency, what should I do?
image

@serengil
Copy link
Owner

serengil commented Dec 9, 2020

could you downgrade other dependencies as mentioned. if it says keras>=2.2.0 then, downgrade keras to 2.2.0 (pip install keras==2.2.0).

@serengil serengil reopened this Dec 13, 2020
@serengil
Copy link
Owner

I fixed this issue. deepface will be compatible with tf 2. I plan to release it tomorrow.

@serengil
Copy link
Owner

this is solved in 0.0.46 release right now.

@shrhawk-entertainer
Copy link

@serengil still the same issue

obj = DeepFace.analyze(img_path = "test_image.jpg", actions = ['age', 'gender', 'race', 'emotion'])

it giving the following error on TensorFlow version 2.3.1

graph = tf.get_default_graph()
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'

@serengil
Copy link
Owner

serengil commented Dec 27, 2020

@shrhawk-entertainer you are using the latest version of deepface - 0.0.49? Because, as you can see here - 86th line, graph = tf.get_default_graph() code is not running for tensorflow 2.

@shrhawk-entertainer
Copy link

@serengil yes I am using version 0.0.49 and the code you mentioned above is for API but I am invoking the deepface from the python shell

from deepface import DeepFace
obj = DeepFace.analyze(img_path = "test_image.jpg", actions = ['age', 'gender', 'race', 'emotion'])

the traceback error is

envname/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py", line 74, in get_uid
  graph = tf.get_default_graph()
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'

@serengil
Copy link
Owner

could you share the all log here. I could not understand where this error come from. Which line of the deepface.py.

@shrhawk-entertainer
Copy link

here's the complete log

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/shrhawk/envname/lib/python3.7/site-packages/deepface/DeepFace.py", line 309, in analyze
    functions.initialize_detector(detector_backend = detector_backend)
  File "/Users/shrhawk/envname/lib/python3.7/site-packages/deepface/commons/functions.py", line 136, in initialize_detector
    face_detector = MTCNN()
  File "/Users/shrhawk/envname/lib/python3.7/site-packages/mtcnn/mtcnn.py", line 88, in __init__
    self._pnet, self._rnet, self._onet = NetworkFactory().build_P_R_O_nets_from_file(weights_file)
  File "/Users/shrhawk/envname/lib/python3.7/site-packages/mtcnn/network/factory.py", line 123, in build_P_R_O_nets_from_file
    p_net = self.build_pnet()
  File "/Users/shrhawk/envname/lib/python3.7/site-packages/mtcnn/network/factory.py", line 38, in build_pnet
    p_inp = Input(input_shape)
  File "/Users/shrhawk/envname/lib/python3.7/site-packages/keras/engine/input_layer.py", line 178, in Input
    input_tensor=tensor)
  File "/Users/shrhawk/envname/lib/python3.7/site-packages/keras/legacy/interfaces.py", line 91, in wrapper
    return func(*args, **kwargs)
  File "/Users/shrhawk/envname/lib/python3.7/site-packages/keras/engine/input_layer.py", line 39, in __init__
    name = prefix + '_' + str(K.get_uid(prefix))
  File "/Users/shrhawk/envname/lib/python3.7/site-packages/keras/backend/tensorflow_backend.py", line 74, in get_uid
    graph = tf.get_default_graph()
AttributeError: module 'tensorflow' has no attribute 'get_default_graph'

@serengil
Copy link
Owner

Oke I think I understood. MTCNN requires Keras dependency. I am using tensorflow 2.3.1 and keras 2.4.3.

You can either install keras with the command "pip install keras"

Or you can change the face detector backend as shown below

obj = DeepFace.analyze(img_path = "test_image.jpg", actions = ['age', 'gender', 'race', 'emotion'], detector_backend = 'opencv')

@shrhawk-entertainer
Copy link

@serengil Keras is already installed with version 2.2.4

@serengil
Copy link
Owner

as I mentioned, you cannot import MTCNN that's the problem. I can import it with tf 2.3.1 and keras 2.4.3. Upgrading keras to 2.4.3 might solve this but you should try.

You might open an issue to mtcnn repo directly here. I recommend you to use opencv backend as a workaround.

@serengil serengil added the bug Something isn't working label Mar 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants