Models API

class face_engine.models.Model

FaceEngine model base class. Used to register all inheriting and imported subclasses (subclass registration PEP 487).

Note

  • implementing model classes must have name class descriptor

Detector

class face_engine.models.Detector

Human face detector model base class.

Note

  • bounding box format is (left, upper, right, lower)
detect(image)

Detect all faces in the image.

Parameters:image (numpy.ndarray) – RGB Image with shape (rows, cols, 3)
Returns:bounding boxes with shape (n_faces, 4), detector model dependent extra information.
Return type:(numpy.ndarray, dict)
Raises:FaceNotFoundError
name = 'abstract_detector'

Embedder

class face_engine.models.Embedder

This object calculates embedding vectors from the face containing image.

Note

  • implementing model classes should have dim class descriptor
compute_embeddings(image, bounding_boxes, **kwargs)

Compute image embeddings for given bounding boxes

Parameters:
  • image (numpy.ndarray) – RGB image with shape (rows, cols, 3)
  • bounding_boxes (numpy.ndarray) – bounding boxes with shape (n_faces, 4)
  • kwargs – model dependent
Returns:

array of embedding vectors with shape (n_faces, embedding_dim)

Return type:

numpy.ndarray

name = 'abstract_embedder'

Estimator

class face_engine.models.Estimator

Estimator model base class. Used to make predictions for face embedding vectors.

fit(embeddings, class_names, **kwargs)

Fit (train) estimator model with given embeddings for given class names.

Note that the passed number of samples for embbedings and class_names has to be equal.

Parameters:
  • embeddings (numpy.ndarray) – face embedding vectors with shape (n_samples, embedding_dim)
  • class_names (list) – sequence of class names
  • kwargs – model and data dependent
Returns:

self

Raises:

TrainError

predict(embeddings)

Make predictions for given embeddings.

Note

Model previously has to be fitted.

Parameters:embeddings (numpy.array) – array of embedding vectors with shape (n_faces, embedding_dim)
Returns:prediction scores and class names
Return type:(list, list)
Raises:TrainError
name = 'abstract_estimator'
save(dirname)

Persist estimators’s model state to given directory.

File naming format convention:
name = '%s.estimator.%s' % (self.name, ext)
load(dirname)

Restore estimator’s model state from given directory.

File naming format convention:
name = '%s.estimator.%s' % (self.name, ext)