serengil / deepface

A Lightweight Face Recognition and Facial Attribute Analysis (Age, Gender, Emotion and Race) Library for Python
https://bit.ly/deepface-py
MIT License
14.62k stars 2.22k forks source link

'_thread._local' object has no attribute 'value' #37

Closed DevJoris closed 4 years ago

DevJoris commented 4 years ago

Hey there,

I just started with DeepFace and it seemed all to work. But something weirds happen when I put the exact same code (copied from the official page) in a function.

This is the code I try to run:

` try:

            faceinfo = DeepFace.analyze("images/happy.jpeg")
            print('[INFO] Emotion:', faceinfo["dominant_emotion"])
            print('[INFO] Age:', faceinfo["age"])
            print('[INFO] Gender:', faceinfo["gender"])
            print('[INFO] Race:', faceinfo["dominant_race"])

        except Exception as e:
            print(str(e) + ' [FACE INFO]')`

The error i'm getting: '_thread._local' object has no attribute 'value'

Could anyone help me out with this?

serengil commented 4 years ago

could you print faceinfo directly?

DevJoris commented 4 years ago

Printing faceinfo directly works fine

Ill give u all of my code. Im writing a telegram bot that fetches faces from the chat and sends the user info about them

https://pastebin.com/r26h3M4V

Sorry for deleting multiple comments leaked token accendatily

serengil commented 4 years ago

You have faceinfo but you cannot access the values in faceinfo right? I cannot open the web site link you shared.

Could you try to run the following code block and send me the printings.

from deepface import DeepFace

faceinfo = DeepFace.analyze("images/happy.jpeg")

print(resp_obj)

print("-------------------------")

for key, value in resp_obj.items():
    print(key,": ",value)
serengil commented 4 years ago

It seems that you cannot process json objects. Please import json library as well.

DevJoris commented 4 years ago

Adding "import json" did not solve the problem. Also the code u send me above did not work. resp_obj is undefined I assume u meant face info with it.

serengil commented 4 years ago

Right. Could you share the print screen when you run the following code block.

from deepface import DeepFace

faceinfo = DeepFace.analyze("images/happy.jpeg")

print(faceinfo)

print("-------------------------")

for key, value in faceinfo.items():
    print(key,": ",value)
DevJoris commented 4 years ago
Screenshot 2020-05-30 at 15 31 23 Screenshot 2020-05-30 at 15 31 28

It seems to stop at the line: faceinfo = DeepFace.analyze("image/happy.jpeg")

EDIT: This is not a new project. This is the project where I've sent u the code for. The pastebin link is in a couple posts above this one

DevJoris commented 4 years ago

Hmm weird. I get the exact same error when I try to load a model with Keras inside a function.

from keras import load_model

model = load_model(emotions.hdf5)

this will also trow the error

serengil commented 4 years ago

Replace resp_obj to faceinfo please. Then share the print screen again.

DevJoris commented 4 years ago

I get the exact same error message. Removing try and exept gives something weird. It will just say: Actions to do: ['emotion', 'age', 'gender', 'race']. And then stay on it. No error message nothing. Endless this

serengil commented 4 years ago

what was your tf and keras versions?

could you reinstall them for the following versions

pip install tensorflow==1.9.0 pip install keras==2.2.0

DevJoris commented 4 years ago

I have stopped using keras. I wanted to use your library now. Also pip install tensorflow==1.9.0 does not work. There is no tensor flow 1.9.0?

DevJoris commented 4 years ago

Collecting tensorflow==1.9.0 Could not find a version that satisfies the requirement tensorflow==1.9.0 (from versions: 1.13.0rc1, 1.13.0rc2, 1.13.1, 1.13.2, 1.14.0rc0, 1.14.0rc1, 1.14.0, 1.15.0rc0, 1.15.0rc1, 1.15.0rc2, 1.15.0rc3, 1.15.0, 1.15.2, 1.15.3, 2.0.0a0, 2.0.0b0, 2.0.0b1, 2.0.0rc0, 2.0.0rc1, 2.0.0rc2, 2.0.0, 2.0.1, 2.0.2, 2.1.0rc0, 2.1.0rc1, 2.1.0rc2, 2.1.0, 2.1.1, 2.2.0rc0, 2.2.0rc1, 2.2.0rc2, 2.2.0rc3, 2.2.0rc4, 2.2.0) No matching distribution found for tensorflow==1.9.0

serengil commented 4 years ago

Interesting. Here, you can check the tf 1.9.0

https://pypi.org/project/tensorflow/1.9.0/

Please try 1.13.1

DevJoris commented 4 years ago

1.13.1 did work. Im now installing it

DevJoris commented 4 years ago

Using tensor flow 1.13.1 worked!

I do get some errors

1:

/Users/Joris/PycharmProjects/TestMode/venv/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'. _np_qint8 = np.dtype([("qint8", np.int8, 1)])

2:

WARNING:tensorflow:From /Users/Joris/PycharmProjects/TestMode/venv/lib/python3.7/site-packages/tensorflow/python/ops/resource_variable_ops.py:435: colocate_with (from tensorflow.python.framework.ops) is deprecated and will be removed in a future version. Instructions for updating:

But it did successfully get the emotions and everything! :D

serengil commented 4 years ago

these are warnings. you can discard and ignore.

happy to hear that.

DevJoris commented 4 years ago

Anyway how I can turn them off? I won't bother u anymore after this :D Anyways really really really thankful. Thanks for fast replies :D

DevJoris commented 4 years ago

Using os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3' stops the second error but not the first