pepper.framework.sensor.face module

class pepper.framework.sensor.face.Face(name, confidence, representation, bounds, image)[source]

Bases: pepper.framework.sensor.obj.Object

Face Object

Parameters:
  • name (str) – Name of Person
  • confidence (float) – Name Confidence
  • representation (np.ndarray) – Face Feature Vector
  • bounds (Bounds) – Face Bounding Box
  • image (AbstractImage) – Image Face was Found in
UNKNOWN = 'Stranger'
representation

Face Representation

Returns:representation – Face Feature Vector
Return type:np.ndarray
class pepper.framework.sensor.face.FaceClassifier(people, n_neighbors=20)[source]

Classify Faces of People

Parameters:
  • people (Dict[str, np.ndarray]) – Known People as <name, representations> dictionary
  • n_neighbors (int) –
NEW = 'NEW'
accuracy()[source]

Calculate Classifier Cross Validation Accuracy

Returns:accuracy
Return type:float
add(name, vector)[source]

Add Person to Face Classifier

Parameters:
  • name (str) –
  • vector (np.ndarray) – Concatenated Representations (float32 array of length 128n)
classify(representation, bounds, image)[source]

Classify Face Observation as Particular Person

Parameters:
  • representation (np.ndarray) – Observed Face Representation (from OpenFace.represent)
  • bounds (Bounds) – Face Bounds (relative to Image)
  • image (AbstractImage) – Image in which Face was Observed
Returns:

person – Classified Person

Return type:

Face

classmethod from_directory(directory)[source]

Construct FaceClassifier from directory of <name>.bin files

Parameters:directory (str) –
Returns:face_classifier
Return type:FaceClassifier
static load_directory(directory)[source]

Load People from directory of <name>.bin files

Parameters:directory (str) –
Returns:people – Dictionary of <name>: <representations> pairs
Return type:dict
people

People Dictionary

Returns:people
Return type:dict
class pepper.framework.sensor.face.FaceStore[source]

Bases: object

EXTENSION = '.bin'
static load_directories(*directories)[source]
static load_directory(directory)[source]

Load all faces from directory with <name>.<FaceStore.EXTENSION> files

Parameters:directory (str) – Directory containing Face Data
Returns:faces – Dictionary of {name: representation} pairs
Return type:Dict[str, np.ndarray]
static load_face(path)[source]

Load Face in a <name>.<FaceStore.EXTENSION> file

Parameters:path (str) –
Returns:name, representation
Return type:str, np.ndarray
static save_face(directory, name, data)[source]

Save Face to directory in a <name>.<FaceStore.EXTENSION> file

Parameters:
  • directory (str) – Directory containing Face Data
  • name (str) – Name of Person
  • data (List[np.ndarray]) – List of Representations: See OpenFace.represent(image) -> Face
class pepper.framework.sensor.face.OpenFace[source]

Bases: object

Perform Face Recognition Using OpenFace

This requires a Docker Image of `bamos/openface` and Docker Running, see The Installation Guide

If not yet running, this class will:
  1. run the bamos/openface container
  2. copy /util/_openface.py to it
  3. run the server included within the container

It will then connect a client to this server to request face representations via a socket connection.

DOCKER_IMAGE = 'bamos/openface'
DOCKER_NAME = 'openface'
DOCKER_WORKING_DIRECTORY = '/root/openface'
FEATURE_DIM = 128
HOST = '127.0.0.1'
PORT = 8989
SCRIPT_NAME = '_openface.py'
SCRIPT_PATH = 'C:\\Users\\Pepper\\Documents\\Pepper\\pepper\\pepper\\framework\\sensor\\util\\_openface.py'
represent(image)[source]

Represent Face in Image as 128-dimensional vector

Parameters:image (np.ndarray) – Image (possibly containing a human face)
Returns:result – List of (representation, bounds)
Return type:list of (np.ndarray, Bounds)
stop()[source]

Stop OpenFace Image