otaha178/Emotion-recognition

NameError: name 'preds' is not defined

Closed this issue · 6 comments

Hello Omar Ayman,
I find this Project very interesting so I tried it. but when the model does not detect any face then line 53 thoughts error because the 'preds' is defined inside the if condition.
Thank You :-)

Hey man,
this error appears sometimes and i can't find a reason why is this error raising but what i did is that whenever it appears i run the script again and it worked, stupid solution till i find what really causing it.

I'm exactly the same, but as much as I run the script does not work: this is my log:
Using TensorFlow backend.
2018-10-31 19:07:29.243116: I tensorflow/core/platform/cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2018-10-31 19:07:29.494922: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1411] Found device 0 with properties:
name: TITAN V major: 7 minor: 0 memoryClockRate(GHz): 1.455
pciBusID: 0000:01:00.0
totalMemory: 12.00GiB freeMemory: 9.67GiB
2018-10-31 19:07:29.502864: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1490] Adding visible gpu devices: 0
2018-10-31 19:07:30.692378: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-10-31 19:07:30.696807: I tensorflow/core/common_runtime/gpu/gpu_device.cc:977] 0
2018-10-31 19:07:30.699723: I tensorflow/core/common_runtime/gpu/gpu_device.cc:990] 0: N
2018-10-31 19:07:30.709265: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1103] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 9272 MB memory) -> physical GPU (device: 0, name: TITAN V, pci bus id: 0000:01:00.0, compute capability: 7.0)
Traceback (most recent call last):
File "real_time_video.py", line 53, in
for (i, (emotion, prob)) in enumerate(zip(EMOTIONS, preds)):
NameError: name 'preds' is not defined

Add a line "else: continue" after the condition code "if len(faces) > 0:", then run the script and it will work.

Python code line Structure error causing this problem. the solution for this is to manage the for loop in a structured way so that it will able to read 'preds'.

Problem :
problem

Solution :
Solution

Hope you have found what you were looking For. :)

#20 PR with fixing

just add this line :

else:
continue

Screenshot from 2019-11-11 15-44-37