This application tracks the emotions of faces Realtime using the camera. Open CV is used for drawing rectangles and overlaying text data. Face emotion recognition will be using Deep Face library where the webcam identifies human faces in digital images.
The versions of the Tensorflow and Keras libraries are both 2.2.0
I am getting this error at the moment:
ImportError Traceback (most recent call last)
in 1 import cv2 2 import matplotlib.pyplot as plt ----> 3 from deepface import DeepFace 4 5 faceCascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
d:\myenv\lib\site-packages\deepface\DeepFace.py in 10 import pickle 11 ---> 12 from deepface.basemodels import VGGFace, OpenFace, Facenet, FbDeepFace, DeepID, DlibWrapper, ArcFace, Boosting 13 from deepface.extendedmodels import Age, Gender, Race, Emotion 14 from deepface.commons import functions, realtime, distance as dst
d:\myenv\lib\site-packages\deepface\basemodels\VGGFace.py in 10 from keras.layers import Input, Convolution2D, ZeroPadding2D, MaxPooling2D, Flatten, Dense, Dropout, Activation 11 else: ---> 12 from tensorflow import keras 13 from tensorflow.keras.models import Model, Sequential 14 from tensorflow.keras.layers import Input, Convolution2D, ZeroPadding2D, MaxPooling2D, Flatten, Dense, Dropout, Activation
d:\myenv\lib\site-packages\tensorflow\keras_init_.py in 27 from . import models 28 from . import optimizers ---> 29 from . import preprocessing 30 from . import regularizers 31 from . import utils
d:\myenv\lib\site-packages\tensorflow\keras\preprocessing_init_.py in 10 from . import image 11 from . import sequence ---> 12 from . import text 13 14 del _print_function
d:\myenv\lib\site-packages\tensorflow\keras\preprocessing\text_init_.py in 13 from tensorflow.python.keras.preprocessing.text import one_hot 14 from tensorflow.python.keras.preprocessing.text import text_to_word_sequence ---> 15 from tensorflow.python.keras.preprocessing.text import tokenizer_from_json 16 17 del _print_function
ImportError: cannot import name 'tokenizer_from_json' from 'tensorflow.python.keras.preprocessing.text' (d:\myenv\lib\site-packages\tensorflow\python\keras\preprocessing\text.py)
I tried fixing the issue by uninstalling and installing different versions of tenderflow and keras but it is still not working. Is there a kind sole that has encountered with this kind of issue and can help me please ?
import cv2
from deepface import DeepFace
faceCascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
cap = cv2.VideoCapture(1)
#Check if the webcam is opened correctly
if not cap.isOpened():
cap = cv2.VideoCapture(0)
if not cap.isOpened():
raise IOError("Cannot open webcam")
while True:
ret,frame = cap.read() #Read one image from a video
result = DeepFace.analyze(frame, actions=['emotion'], enforce_detection=False)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(gray,1.1,4)
#Draw a rectangle around the faces
#Draw a rectangle around the faces
for(x,y,w,h) in faces:
cv2.rectangle(frame, (x,y), (x+w, y+h), (0,255,0),2)
font = cv2.FONT_HERSHEY_SIMPLEX
#inserting text on video
cv2.putText(frame,
result['dominant_emotion'],
(50,50),
font,3,
(0,0,255),
2,
cv2.LINE_4)
cv2.imshow('Demo video', frame)
if cv2.waitKey(2) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()