Face Trigger - Utils package¶
Contains modules for performing common utilities.
Submodules¶
face_trigger.utils.common module¶
Module that contains various common utilities.
-
class
face_trigger.utils.common.
RepeatedTimer
(interval, function, *args, **kwargs)¶ Bases:
object
Creates a timer object that can call a specified function repeatedly after a specified delayed. Does not drift over time.
-
start
()¶ Starts the timer thread and schedules the next call
-
stop
()¶ Stops the timer thread
-
-
face_trigger.utils.common.
clamp_rectangle
(x1=None, y1=None, x2=None, y2=None, x1_min=0, y1_min=0, x2_max=None, y2_max=None)¶ Clamps the coordinates of a rectangle to within specified limits
Parameters: - x1 (int) – the leftmost x-coordinate
- y1 (int) – the topmost y-coordinate
- x2 (int) – the rightmost x-coordinate
- y2 (int) – the bottommost y-coordinate
- x1_min (int) – the leftmost possible x-coordinate
- y1 – the topmost possible y-coordinate
- x2 – the rightmost possible x-coordinate
- y2 – the bottommost possible y-coordinate
Returns: clamped coordinates (x1_clamped, y1_clamped, x2_clamped, y2_clamped)
Return type: 4-tuple
-
face_trigger.utils.common.
shape_to_np
(shape, dtype='int')¶ Convert a dlib.shape to a numpy array
Parameters: shape (dlib.shape) – a dlib.shape object Returns: converted numpy array Return type: numpy.array
face_trigger.utils.data module¶
Module that contains functions related to dataset cleaning.
-
class
face_trigger.utils.data.
Dataset
(dataset_path=None, split_path=None)¶ A class for generating manual train-test splits and loading data from generated splits.
>>> dataset = Dataset(dataset_path="/media/ankurrc/new_volume/softura/facerec/datasets/norm_standard_att") >>> folds = 3 >>> training_samples = [2, 5, 8] >>> dataset.split(num_train_list=training_samples, folds=folds, split_path="/media/ankurrc/new_volume/softura/facerec/split_path")
-
load_data
(split_path=None, is_train=None, num_train=None, fold=None)¶ Gets the test or train data
Parameters: - is_train (bool) – a flag to indicate whether we need training data or test data
- fold (int) – the fold for which data needs to be loaded
- num_train (int) – the subdirectory indicating number of training samples per subject
- split_path (str) – path to store the dataset train-test split information. Will rename the old directory, if it exists.
Returns: a tuple of a vector of faces and it’s corresponding labels
Return type: (numpy.ndarray, numpy.ndarray)
-
split
(split_path=None, num_train_list=None, folds=1)¶ Generates a train-test split based on the number of training samples
Parameters: - num_train_list (list of inttegers) – number of training samples per fold
- fold (int) – total number of folds
- split_path (str) – path to store the dataset train-test split information. Will rename the old directory, if it exists.
-
-
face_trigger.utils.data.
dataset_filter
(dataset_path=None, output_path=None)¶ Filter the dataset by: 1. A face is detected in the image. If no face or more than one face is detected, the image is rejected. 2. For each detected face, 5-landmarks are detected. If landmarks are not detected, image is rejected. 3. A new dataset is created by not including the rejected images.
Parameters: - dataset_path (str) – path to the original dataset
- output_path (str) – path to the filtered dataset
Returns: dictionary of rejected images
Return type: dict
>>> dataset_path = "/media/ankurrc/new_volume/softura/facerec/datasets/standard_att_copy" >>> output_path = "/media/ankurrc/new_volume/softura/facerec/att_norm"
>>> dataset_filter( dataset_path=dataset_path, output_path=output_path)
-
face_trigger.utils.data.
get_jittered_images
(image_path, num_jitters=5, disturb_colors=False)¶
face_trigger.utils.train module¶
Module that contains functions for loading embeddings from dataset during training.
-
face_trigger.utils.train.
generate_embeddings_for_dataset
(dataset_path=None)¶ Generates embeddings by sequentially reading images from the dataset.
Parameters: dataset_path – path to the dataset Returns: X, y where X is a list of numpy array (128-d vectors) and y is a numpy array representing the labels
-
face_trigger.utils.train.
generate_embeddings_for_split_and_fold
(dataset_path=None, split_path=None, fold=None, num_train=None)¶ Generate embeddings of dataset for a particular split and fold.
Parameters: - dataset_path (str) – path to the dataset
- split_path (str) – path to the directory holding train-test split info
- fold (int) – which fold to generate embeddings on
- num_train (int) – folder name, indacating the number of training samples per subject
Returns: X_train, y_train, X_test, y_test