niccofine/Lie-Detection 是一个托管在 GitHub 上的开源项目,主要使用 Jupyter Notebook 编写,采用 Other 许可证。
仓库全名
niccofine/Lie-Detection
README 摘要
Lie-Detector Machine Learning-based lie detector ensemble system on RGB or RGB-D video-acquired frames using Python. Lie Detector ensemble system using RGB / RGB-D images acquired with webcam / RealSense camera during speech, using blendshapes extracted from RGB images through Mediapipe Face Landmarker, FLAME coeffients extracted from blendshapes, patched RGB image / depth map local binary pattern histograms…
Machine Learning-based lie detector ensemble system on RGB or RGB-D video-acquired frames using Python.
Lie Detector ensemble system using RGB / RGB-D images acquired with webcam / RealSense camera during speech, using blendshapes extracted from RGB images through Mediapipe Face Landmarker, FLAME coeffients extracted from blendshapes, patched RGB image / depth map local binary pattern histograms extracted from the face area detected through Mediapipe Face Detector.
Once downloaded the Jupyter notebook, follow instructions contained in the script, installing the required packages:
The above-presented pipeline can be followed step by step running different script modalities:
Video acquisition: to acquire and save a video recording to be later analysed.
Data can be acquired using two different sources:
Livestream: the data is acquired from the connected RealSense RGB-D camera in real time, or, in case no RealSense camera is connected, from the webcam, requiring to indicate label (Truth or Lie), saving the video as a .bag file (an .avi file in case of webcam acquisition) having as filename a unique time-based ID and the indicated label, stored in the {ID} folder created (if not existing) inside the path specified (if no path is specified then it is saved in the same path where the script is located);
Load video: the data is acquired from a .bag RGB-D video or an .avi RGB video (having as filename a unique time-based ID and the associated label) to be locally selected.
To stop the acquisition or to stop the video evaluation at a certain frame, press the ESC key.
Feature extraction: a single video is loaded, specifying its path, and analysed in order to extract labeled features, with possible choice among:
Blendshapes: blendshapes coeffients frame by frame detected by the MediaPipe Face Landmarker;
Flame: Flame coefficients frame by frame obtained from the extracted blenshapes;
Landmarks: landmarks frame by frame extracted by MediaPipe Face Landmarker, using 3D real value in case of a .bag video (otherwise predicted);
LBP: histogram values of RGB or depth image patches with local binary pattern.
The obtained results are saved in the /Data/Labeled/{ID} folder as an {ID}_{Feature}.csv file, with a unique time-based ID.
Dataset creation: selecting a specific feature type, all the corresponding .csv files extracted in /Data/Labeled/ are used to create a unique dataset made of training, validation and test set (with (80/20)/30 division) for models training / validating / testing, exporting it using a unique time-based ID in the Data/Aggregated/{Feature}/{ID}/Dataset/ folder (output files with associated filename {ID}_{setType}.csv) along a model file containing the training + validation sets scaler for feature min-max scaling (output file with associated filename {ID}_scaler.plk).
The sets are created in order to maintain in each one of them all the data from the same person (avoiding person’s data spanning across multiple sets), along with stratified class assignment for class-balanced sets as the same subject has two class-opposite acquisitions with consecutional IDs.
Multiple feature-types selection allows to in parallel create separate datasets for all the features selected, maintaining in each set the same acquisition IDs.
Statistical analysis: selecting the ID folder of an aggregated feature (Data/Aggregated/{Feature}/{ID}), the current dataset can be analysed statistically for further information:
MANOVA: performing Multivariate ANalysis Of VAriance in order to define if the output class is statistically relevant with all the set of features of the current dataset (a p-value under $0.05$ means a statistic relevance);
PCA: performing Principal Component Analysis in order to define if feature selection methods are necessary, analysing the number of Principal Components (linear combination of features) are necessary to take in consideration the dataset intrinsic variability (considering at least a $99.95%$ of dataset variability to be explained), visualizing the elements of the dataset in a scatter plot with coordinates defined by the first three Principal Components, visualizing them with different color for class differentiation.
Feature selection: selecting the ID folder of an aggregated feature (Data/Aggregated/{Feature}/{ID}), feature selection is performed on the training + validation set to obtain the best set of features; among the possible methods, it is possible to try:
RFE: Recursive Feature Elimination from feature ranking obtained with a Random Forest algorithm;
Lasso: shrinking features’ L1 coefficients toward zero, selecting only the non-zero ones;
MRMR: ranking Minimum Redundancy Maximum Relevance features, measuring the latter using a Random Forest algorithm, selecting the best $20%$ features;
Boruta: selecting the best feature based on several Random Forest classifiers results using various sets of real and shadow features.
The name of the selected set of features is then saved in the Data/Aggregated/{Feature}/{ID}/FeatureSelection folder using the same time-based ID explained (output files with associated filename {ID}_FS_{FSMethod}.txt).
Multiple feature-types selection allows to in parallel create separate feature selections for the dataset selected.
Classifier training: selecting the ID folder of an aggregated feature (Data/Aggregated/{Feature}/{ID}), each available feature selection method applied is used to reduce the training, validation and test set, using the first to train, the second to validate and the third to test the classifier; among the possible classifiers, it is possible to select:
RF: using Random Forest classifiers, training $40$ classifiers changing the model’s hyperparameter (number of trees, ranging from $100$ to $500$ with a step of $10$);
SVM: using Support Vector Machine classifiers with Radial Basis Function, training $16$ classifiers changing the model’s hyperparameters (control error, $10^n$ with $n\in[-1, 2]$, gamma, $10^m$ with $m\in[-3, 0]$);
AdaBoost: using Adaptive Boosting classifiers, training $40$ classifiers changing the model’s hyperparameter (number of extimators, ranging from $100$ to $500$ with a step of $10$).
From all the models obtained from the same-type classifier and same-type feature selection method training, only the best performing one on the validation set (using as metrics the balanced accuracy result on frames’ prediction) is saved (output file with associated filename {ID}_{ClassifierType}_{FSMethod}.pkl), along with the metrics obtained (output file with associated filename {ID}_{ClassifierType}_{FSMethod}_metrics.csv) on the training, validation and test set (balanced accuracy, precision, recall, specificity, sensitivity, F1-score) both in the Data/Aggregated/{Feature}/{ID}/Classifiers folder.
Multiple classifier-types selection allows to in parallel train separate type of models for the dataset selected.
Ensemble evaluation: selecting the ID folder of an aggregated feature (Data/Aggregated/{Feature}/{ID}), the single-best trained models for each feature type sharing the same dataset ID (evaluated on the balanced accuracy of the validation set) are used for inference on the labeled training, validation and test set, to evaluate the method’s performances implementing an ensemble method (excluding frames not extracted using at least one feature extraction method) to have a robust prediction, using two different approaches:
Frame-based: a majority voting is applied for each frame, with the metrics evaluated comparing the majority predictions on each frame and the ground truth class associated to that frame;
ID-based: a score-based class assignment system decides the class for each single ID, with the metrics evaluated comparing the aggregated predictions on each ID and the ground truth class associated to that ID.
The score is obtained from the percentages of frames that each classifier assigns to truth or lie, creating truth and lie scores by summing the above-mentioned percentages across the classifiers, and computing a final decision score by subtracting the truth score and the lie score; if the score is above $30$ or $\in[-30,0)$ then the assigned class is Truth, otherwise (except for zero score, which is assigned thanks to a simple majority voting system based on classifiers’ total prediction) Lie.
Lie evaluation: selecting the ID folder of an aggregated feature (Data/Aggregated/{Feature}/{ID}), the single-best trained models for each feature type sharing the same dataset ID (evaluated on the frames’ balanced accuracy of the validation set) are used for inference on the acquired data, implementing a score-based class assignment system to have a robust prediction; the video acquisition and feature extraction phase is performed as previously described, saving the results in the /Data/Unlabeled/ folder.
评论