Package: fer
FERFacial expression recognition.INSTALLATIONCurrently FER only supports Python 3.6 onwards. It can be installed
through pip:$pipinstallferThis implementation requires OpenCV>=3.2 and Tensorflow>=1.7.0
installed in the system, with bindings for Python3.They can be installed through pip (if pip version >= 9.0.1):$pipinstalltensorflow>=1.7opencv-contrib-python==3.3.0.9or compiled directly from sources
(OpenCV3,Tensorflow).Note that a tensorflow-gpu version can be used instead if a GPU device
is available on the system, which will speedup the results. It can be
installed with pip:$pipinstalltensorflow-gpu\>=1.7.0To extract videos that includes sound, ffmpeg and moviepy packages must be installed with pip:$pipinstallffmpegmoviepyUSAGEThe following example illustrates the ease of use of this package:fromferimportFERimportcv2img=cv2.imread("justin.jpg")detector=FER()detector.detect_emotions(img)Sample output:[{'box': [277, 90, 48, 63], 'emotions': {'angry': 0.02, 'disgust': 0.0, 'fear': 0.05, 'happy': 0.16, 'neutral': 0.09, 'sad': 0.27, 'surprise': 0.41}]Pretty print it withimport pprint; pprint.pprint(result).Just want the top emotion? Try:emotion,score=detector.top_emotion(img)# 'happy', 0.99MTCNN Facial RecognitionFaces by default are detected using OpenCV's Haar Cascade classifier. To use the more accurate MTCNN network,
add the parameter:detector=FER(mtcnn=True)VideoFor recognizing facial expressions in video, theVideoclass splits video into frames. It can use a local Keras model (default) or Peltarion API for the backend:fromferimportVideofromferimportFERvideo_filename="tests/woman2.mp4"video=Video(video_filename)# Analyze video, displaying the outputdetector=FER(mtcnn=True)raw_data=video.analyze(detector,display=True)df=video.to_pandas(raw_data)The detector returns a list of JSON objects. Each JSON object contains
two keys: 'box' and 'emotions':The bounding box is formatted as [x, y, width, height] under the key
'box'.The emotions are formatted into a JSON object with the keys 'anger',
'disgust', 'fear', 'happy', 'sad', surprise', and 'neutral'.Other good examples of usage can be found in the filesdemo.pylocated in the root of this repository.To run the examples, install click for command line withpip install clickand enterpython demo.py [image|video|webcam]--help.TF-SERVINGSupport running with online TF Serving docker image.To use: Rundocker-compose upand initialize FER withFER(..., tfserving=True).MODELFER bundles a Keras model.The model is a convolutional neural network with weights saved to HDF5
file in thedatafolder relative to the module's path. It can be
overriden by injecting it into theFER()constructor during
instantiation with theemotion_modelparameter.LICENSEMIT License.CREDITThis code includes methods and package structure copied or derived from
Iván de Paz Centeno'simplementationof MTCNN and Octavio Arriaga'sfacial expression recognition
repo.REFERENCEFER 2013 dataset curated by Pierre Luc Carrier and Aaron Courville, described in:"Challenges in Representation Learning: A report on three machine learning contests," by Ian J. Goodfellow, Dumitru Erhan, Pierre Luc Carrier, Aaron Courville, Mehdi Mirza, Ben Hamner, Will Cukierski, Yichuan Tang, David Thaler, Dong-Hyun Lee, Yingbo Zhou, Chetan Ramaiah, Fangxiang Feng, Ruifan Li, Xiaojie Wang, Dimitris Athanasakis, John Shawe-Taylor, Maxim Milakov, John Park, Radu Ionescu, Marius Popescu, Cristian Grozea, James Bergstra, Jingjing Xie, Lukasz Romaszko, Bing Xu, Zhang Chuang, and Yoshua Bengio,arXiv:1307.0414.