The repo contains an audio emotion detection model, facial emotion detection model, and a model that combines both these models to predict emotions from a video
95
stars
25
commits
Jupyter Notebook
primary language
Sep 13, 2023
updated
This multimodal emotion detection model predicts a speaker's emotion using audio and image sequences from videos. The repository contains two primary models: an audio tone recognition model with a CNN for audio-based emotion prediction, and a facial emotion recognition model using a CNN and optional mediapipe face landmarks for facial emotion prediction. The third model combines a video clip's audio and image sequences, processed through an LSTM for speaker emotion prediction. Hyperparameters such as landmark usage, CNN model selection, LSTM units, and dense layers are tuned for optimal accuracy using included modules. For new datasets, follow the instructions below to retune the hyperparameters.
![]() | ![]() | ![]() |
![]() | ![]() | ![]() |
![]() | ![]() | ![]() |
![]() | ![]() | ![]() |
angry_alex.mp4
Prediction labels:
Sad/Fear: 0.0%
Neutral: 0.0%
Happy: 0.0%
Angry: 100.0%
Surprise/Disgust: 0.0%
audio_happy.mp4
Prediction labels:
Sad/Fear: 0.0%
Neutral: 0.0%
Happy: 100.0%
Angry: 0.0%
Surprise/Disgust: 0.0%
<Program implemented, display items yet to be added>
git clone https://github.com/rishiswethan/Video-Audio-Face-Emotion-Recognition.gitcd Video-Audio-Face-Emotion-Recognitiongit clone https://github.com/rishiswethan/pytorch_utils.git source/pytorch_utilscd source/pytorch_utils && git checkout v1.0.3 && cd ../..python -m venv venvsource venv/bin/activatevenv\Scripts\activatepip install -r requirements.txtpython -m spacy download en_core_web_lgpip uninstall torchpip cache purgepip3 install torch==1.13.1+cu117 torchvision>=0.13.1+cu117 torchaudio>=0.13.1+cu117 --extra-index-url https://download.pytorch.org/whl/cu117 --no-cache-dir
pip install torchpython setup.pypython run.py
config.py for a
glimpse of the correct way to set file paths. The data should be in the following format. The preprocessing code will read the files names and infer the emotion from it.
get_data.py from all model folders will help you format this data. Have a look at the code and
how the functions for each dataset are called. You can use the same functions to format your data, or write your own functions to get the below format.config.py file. The default is the final commit.
data
├───training_AV // Audio visual data used for training the combined model
│ ├───RAVDESS
│ │ ├───train
│ │ │ ├───RAVDESS_0_Neurtal.mp4 // Example
│ │ │ ├───<dataset_name>_<s.no>_<emotion>.mp4 // Correct format
│ │ │ ├───...other videos
│ │ ├───test
│ │ │ ├───<dataset_name>_<s.no>_<emotion>.mp4
│ // Other datasets must be added in the same format and added in the config.py file
│
├───training_faces // Facial data used for training the landmarks and image based emotion detection model
│ ├───FER
│ │ ├───train
│ │ │ ├───FER_0_Angry.png
│ │ │ ├───<dataset_name>_<s.no>_<emotion>.png // Correct format
│ │ │ ├───...other images
│ │ ├───test
│ │ │ ├───<dataset_name>_<s.no>_<emotion>.png // Test data from all faces datasets are used
│
├───extracted_audio // Audio data used for training the audio model
│ ├───RAVDESS
│ │ ├───train
│ │ │ ├───RAVDESS_0_Neurtal.wav // Example
│ │ │ ├───<dataset_name>_<s.no>_<emotion>.wav // Correct format
│ │ │ ├───...other audio
│ │ ├───test
│ │ │ ├───<dataset_name>_<s.no>_<emotion>.wav // We only use testing data from CREMA-D and TESS, this is just an example. The downloaded data will be empty here.
config.py file is used to simplify the emotions by combining them. Use it to combine emotions for which there is not enough data,
like "surprise" for which there was very little data, so I combined it with disgust. You can disable this simplification by setting the
EMOTION_INDEX to FULL_EMOTION_INDEX, and EMOTION_INDEX_REVERSE to FULL_EMOTION_INDEX_REVERSE in the config.py file.<dataset_name>_<s.no>_<emotion_index>.<file_extension>FULL_EMOTION_INDEX in the config.py file. For example, if the emotion is 'happy', the index is 3.FULL_EMOTION_INDEX dict of the config.py file. Simplifying is only done when the preprocessed data
is used for training. Before that, we only use all the emotions in the FULL_EMOTION_INDEX dict as you can see in the dataset provided.config.py
file's VIDEO_ANALYSE_WINDOW_SECS variable. If videos in the training set are longer, only the last x seconds will be used. If they are shorter, they will be padded to meet the window size.
get_data.py file of the combined model. You can use it as well.ALL_EXTRACTED_<model_name>_FOLDERS path list. You'll have a clearer understanding if you look at how
I wrote the various paths for this in the config.py file.run.py is the main file. It contains the menu to run the various options. You can use this as a reference to see how to call the various functions in your
customised implementation.setup.py nothing fancy, just creates the empty folders like inputs, outputs, etc.source/config.py contains all the file paths, and general constants used by all the models.source/<model_name>/<model_name>_config.py contains all the model specific constants, such as initial learning rate, scheduler configs and hyperparameters tuning ranges.source/<model_name>/<model_name>_model.py contains the model architecture.source/<model_name>/<model_name>_preprocess_main.py contains the code to preprocess the data and store it as .npy files in the
data/preprocessed_<model_name>_data foldersource/<model_name>/utils.py contains all the utility functions used by the model. Some of them are used by all the models, and some are specific to the model.source/<model_name>/predict.py contains the code to predict the emotion of a file.source/<model_name>/get_data.py contains the code to format the data into the correct format for the preprocessing code to read, as mentioned above.data/preprocessed_<model_name>_data contains the preprocessed .npy data files. These are the files that are used to train the model.data/original_<dataset_name>_data contains the original, unaltered data files. You can format them into the training_AV, training_face and extracted audio
folders using the get_data.py program, or your own.models contains the trained models, best hyperparameters and the tuning logs. Note that the model trained based on the best config, may not be have the exact
performance as you see in the tuning logs. This is because, the model is retrained using random initialization, and it won't converge to the same minima as it did during tuning.
But the difference in performance should be negligible.input_files contains the input files of the predict program. This is where the file name of your input will be searched for, when you run run.py.output_files contains the output files of the predict program.data/preprocessed_<model_name>_data folder. Preprocessing takes way too long, and it's not
possible to preprocess the data on the fly, so we preprocess it once and store it. This also makes it easier to tune the hyperparameters, as we can use the same preprocessed
data for all the hyperparameter tuning runs.VIDEO_ANALYSE_WINDOW_SECS second videos.FRAME_RATE frames per second.I've made this project public so that it can be used by anyone who wants to use it. I've tried to make it as easy to use as possible, but if you have any questions or suggestions, create an issue or discuss it in the discussions section. I'll try to answer them as soon as possible. If you want to contribute, create a pull request. I'll try to review it as soon as possible.
25 commits
Jupyter Notebook
94.5%
Python
5.5%
The repo contains an audio emotion detection model, facial emotion detection model, and a model that combines both these models to predict emotions from a video
95
stars
25
commits
Jupyter Notebook
primary language
Sep 13, 2023
updated
This multimodal emotion detection model predicts a speaker's emotion using audio and image sequences from videos. The repository contains two primary models: an audio tone recognition model with a CNN for audio-based emotion prediction, and a facial emotion recognition model using a CNN and optional mediapipe face landmarks for facial emotion prediction. The third model combines a video clip's audio and image sequences, processed through an LSTM for speaker emotion prediction. Hyperparameters such as landmark usage, CNN model selection, LSTM units, and dense layers are tuned for optimal accuracy using included modules. For new datasets, follow the instructions below to retune the hyperparameters.
![]() | ![]() | ![]() |
![]() | ![]() | ![]() |
![]() | ![]() | ![]() |
![]() | ![]() | ![]() |
angry_alex.mp4
Prediction labels:
Sad/Fear: 0.0%
Neutral: 0.0%
Happy: 0.0%
Angry: 100.0%
Surprise/Disgust: 0.0%
audio_happy.mp4
Prediction labels:
Sad/Fear: 0.0%
Neutral: 0.0%
Happy: 100.0%
Angry: 0.0%
Surprise/Disgust: 0.0%
<Program implemented, display items yet to be added>
git clone https://github.com/rishiswethan/Video-Audio-Face-Emotion-Recognition.gitcd Video-Audio-Face-Emotion-Recognitiongit clone https://github.com/rishiswethan/pytorch_utils.git source/pytorch_utilscd source/pytorch_utils && git checkout v1.0.3 && cd ../..python -m venv venvsource venv/bin/activatevenv\Scripts\activatepip install -r requirements.txtpython -m spacy download en_core_web_lgpip uninstall torchpip cache purgepip3 install torch==1.13.1+cu117 torchvision>=0.13.1+cu117 torchaudio>=0.13.1+cu117 --extra-index-url https://download.pytorch.org/whl/cu117 --no-cache-dir
pip install torchpython setup.pypython run.py
config.py for a
glimpse of the correct way to set file paths. The data should be in the following format. The preprocessing code will read the files names and infer the emotion from it.
get_data.py from all model folders will help you format this data. Have a look at the code and
how the functions for each dataset are called. You can use the same functions to format your data, or write your own functions to get the below format.config.py file. The default is the final commit.
data
├───training_AV // Audio visual data used for training the combined model
│ ├───RAVDESS
│ │ ├───train
│ │ │ ├───RAVDESS_0_Neurtal.mp4 // Example
│ │ │ ├───<dataset_name>_<s.no>_<emotion>.mp4 // Correct format
│ │ │ ├───...other videos
│ │ ├───test
│ │ │ ├───<dataset_name>_<s.no>_<emotion>.mp4
│ // Other datasets must be added in the same format and added in the config.py file
│
├───training_faces // Facial data used for training the landmarks and image based emotion detection model
│ ├───FER
│ │ ├───train
│ │ │ ├───FER_0_Angry.png
│ │ │ ├───<dataset_name>_<s.no>_<emotion>.png // Correct format
│ │ │ ├───...other images
│ │ ├───test
│ │ │ ├───<dataset_name>_<s.no>_<emotion>.png // Test data from all faces datasets are used
│
├───extracted_audio // Audio data used for training the audio model
│ ├───RAVDESS
│ │ ├───train
│ │ │ ├───RAVDESS_0_Neurtal.wav // Example
│ │ │ ├───<dataset_name>_<s.no>_<emotion>.wav // Correct format
│ │ │ ├───...other audio
│ │ ├───test
│ │ │ ├───<dataset_name>_<s.no>_<emotion>.wav // We only use testing data from CREMA-D and TESS, this is just an example. The downloaded data will be empty here.
config.py file is used to simplify the emotions by combining them. Use it to combine emotions for which there is not enough data,
like "surprise" for which there was very little data, so I combined it with disgust. You can disable this simplification by setting the
EMOTION_INDEX to FULL_EMOTION_INDEX, and EMOTION_INDEX_REVERSE to FULL_EMOTION_INDEX_REVERSE in the config.py file.<dataset_name>_<s.no>_<emotion_index>.<file_extension>FULL_EMOTION_INDEX in the config.py file. For example, if the emotion is 'happy', the index is 3.FULL_EMOTION_INDEX dict of the config.py file. Simplifying is only done when the preprocessed data
is used for training. Before that, we only use all the emotions in the FULL_EMOTION_INDEX dict as you can see in the dataset provided.config.py
file's VIDEO_ANALYSE_WINDOW_SECS variable. If videos in the training set are longer, only the last x seconds will be used. If they are shorter, they will be padded to meet the window size.
get_data.py file of the combined model. You can use it as well.ALL_EXTRACTED_<model_name>_FOLDERS path list. You'll have a clearer understanding if you look at how
I wrote the various paths for this in the config.py file.run.py is the main file. It contains the menu to run the various options. You can use this as a reference to see how to call the various functions in your
customised implementation.setup.py nothing fancy, just creates the empty folders like inputs, outputs, etc.source/config.py contains all the file paths, and general constants used by all the models.source/<model_name>/<model_name>_config.py contains all the model specific constants, such as initial learning rate, scheduler configs and hyperparameters tuning ranges.source/<model_name>/<model_name>_model.py contains the model architecture.source/<model_name>/<model_name>_preprocess_main.py contains the code to preprocess the data and store it as .npy files in the
data/preprocessed_<model_name>_data foldersource/<model_name>/utils.py contains all the utility functions used by the model. Some of them are used by all the models, and some are specific to the model.source/<model_name>/predict.py contains the code to predict the emotion of a file.source/<model_name>/get_data.py contains the code to format the data into the correct format for the preprocessing code to read, as mentioned above.data/preprocessed_<model_name>_data contains the preprocessed .npy data files. These are the files that are used to train the model.data/original_<dataset_name>_data contains the original, unaltered data files. You can format them into the training_AV, training_face and extracted audio
folders using the get_data.py program, or your own.models contains the trained models, best hyperparameters and the tuning logs. Note that the model trained based on the best config, may not be have the exact
performance as you see in the tuning logs. This is because, the model is retrained using random initialization, and it won't converge to the same minima as it did during tuning.
But the difference in performance should be negligible.input_files contains the input files of the predict program. This is where the file name of your input will be searched for, when you run run.py.output_files contains the output files of the predict program.data/preprocessed_<model_name>_data folder. Preprocessing takes way too long, and it's not
possible to preprocess the data on the fly, so we preprocess it once and store it. This also makes it easier to tune the hyperparameters, as we can use the same preprocessed
data for all the hyperparameter tuning runs.VIDEO_ANALYSE_WINDOW_SECS second videos.FRAME_RATE frames per second.I've made this project public so that it can be used by anyone who wants to use it. I've tried to make it as easy to use as possible, but if you have any questions or suggestions, create an issue or discuss it in the discussions section. I'll try to answer them as soon as possible. If you want to contribute, create a pull request. I'll try to review it as soon as possible.
25 commits
Jupyter Notebook
94.5%
Python
5.5%