src.utils package¶
Subpackages¶
Submodules¶
src.utils.ground_truth module¶
- class src.utils.ground_truth.FaceAPIThread(port: int, logging: bool = False)¶
Bases:
Thread
Thread that runs face-api.js as a background server.
- run() None ¶
Thread run function that starts a subprocess with face-api.js that listens on localhost:self.port/emotions.
- stop()¶
Stop function that stops the subprocess and the API.
- src.utils.ground_truth.experiment_ground_truth(video_file: str) None ¶
Main function that creates ground truth for the experiments using face expression emotions from face-api.js.
- Parameters:
video_file – The video_file to compute the emotions for.
src.utils.metrics module¶
Implement interesting metrics to use them later.
- src.utils.metrics.accuracy(labels: ndarray, prediction: ndarray) float ¶
Compute the accuracy of predictions.
- Parameters:
labels – Labels array.
prediction – Predicitions array from classifier.
- Returns:
Accuracy
- src.utils.metrics.per_class_accuracy(labels: ndarray, prediction: ndarray) float ¶
Compute the average per class accuracy of predictions. This is equivalent to the average recall per class.
- Parameters:
labels – Labels array.
prediction – Predicitions array from classifier.
- Returns:
Per class accuracy average
- src.utils.metrics.precision(labels: ndarray, prediction: ndarray) float ¶
Compute the precision of predictions.
- Parameters:
labels – Labels array.
prediction – Predicitions array from classifier.
- Returns:
Precision
- src.utils.metrics.recall(labels: ndarray, prediction: ndarray) float ¶
Compute the recall of predictions.
- Parameters:
labels – Labels array.
prediction – Predicitions array from classifier.
- Returns:
Recall
src.utils.training module¶
Implement training loops for all the classifiers for testing them.
- src.utils.training.cv_training_loop(classifier, parameters: Dict[str, Any], save_path: Optional[str] = None, cv_splits: int = 5) None ¶
Implements an example training loop for a classifier that is running in cross validation mode. This means that the dataset is split into ‘cv_splits’ subsets, one of them is used for validation, another one for testing and the rest for training. This function trains ‘cv_splits’ separate models in order to get one model for every element in the data. This trains the classifiers, saves the models, then loads the classifiers and runs inference on the test sets. It then prints the accuracy and average accuracy of the different classifiers.
- Parameters:
cv_splits – How many splits to use for the dataset.
classifier – The classifier instance to train here.
parameters – The parameters used for training the classifier.
save_path – The save path to save the classifier at.
- src.utils.training.reader_main(reader, parameters: Optional[Dict[str, Any]]) None ¶
Main method that can be used to see if a data reader works as expected. This creates a dataset and prints the shapes and counts of the classes on the test set.
- Parameters:
reader – The data reader instance to evaluate.
parameters – Parameters for the data reader.
- src.utils.training.training_loop(classifier, parameters: Dict[str, Any], save_path: Optional[str] = None) None ¶
Implements an example training loop for a normal classifier. This trains the classifier, saves the model, then loads the classifier and runs inference on the test set. It then prints the accuracy.
- Parameters:
classifier – The classifier instance to train here.
parameters – The parameters used for training the classifier.
save_path – The save path to save the classifier at.
Module contents¶
Utility functions and other code.