ArcFaceIdentifier
Search for a face and identification in an embedding database
This module provides a pipeline element to search for a face and
identification in the embedding database. This module assumes that the embeddigs
have been created using the ArcFace model. By default the embedding database
is a Redis database. The embedding database uses a Approximately-Nearest-Neighbor
(ANN) algorithm to find the nearest embedding. The embedding database needs to be
populated with embeddings beforehand, there is an example under tools/facial_recognition
.
Databases (<e-database>
) currently supported are:
- Redis (
redis
)
Examples:
REST API:
WIP
Configuration File:
short-from : arcface-identifier:<e-database>
pipeline:
- yolov5s-face:a:0.3:0.3
- demux
- face-alignment
- arcface
- mux
- arcface-identifier:redis:0.3
sources:
- address: videos/sample.mp4
- type: file
is_redis_available
def is_redis_available(rs)
Check if the redis database is available
Arguments:
rs
redis.Redis - Redis database
Returns:
bool
- True if the database is available
Examples:
rs = redis.Redis(host=HOST, port=PORT, db=0)
rs_ready = is_redis_available(rs)
create_embedding_db
def create_embedding_db(database)
Create an embedding database
Arguments:
database
str - The database to use
Returns:
storage
nearpy.storage.storage.Storage - The embedding databaselshash
nearpy.hashes.RandomBinaryProjections - The LSH algorithm
Raises:
RuntimeError
- If the database is not available, or if it is unable to find the EmbeddingHash configuration
Examples:
embedding_storage, lshash = create_embedding_db("redis")
ArcFaceIdentifier Objects
class ArcFaceIdentifier(Element)
Search for an identification in the embedding database and assign it to the detection.
Attributes:
name
str - The name of the elementdatabase
str - The database to usethreshold
float - The threshold to usesupported_database
List[str] - At list of the supported database types
Examples:
ele = ArcFaceIdentifier("redis")
extract_params
| @staticmethod
| def extract_params(model_params)
Extract the parameters for this element.
Arguments:
model_params
List[str] - The parameters for this element.
Returns:
database
str - The database to usethreshold
float - The threshold to use
Raises:
ExtractParameterException
- If the parameters are not valid.
Examples:
params = ArcFaceIdentifier.extract_params(["redis", "0.3"])
ele = ArcFaceIdentifier(params)
process
| def process(meta)
Process the detections and assign the identification to the detection.
This is the main function for the element. It takes the detection and searches for the identification in the embedding database. If the identification string is found, the detection is assigned the identification. It also includes the three nearest neighbours as candidates.
Arguments:
meta
dict - The metadata to process.
Returns:
meta
dict - The processed metadata.
Examples:
params = ArcFaceIdentifier.extract_params(["redis", "0.3"])
ele = ArcFaceIdentifier(params)
meta = ele.process(meta)