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 embeddings
have been created using the ArcFace model. By default, the embedding database
is a Redis database. The embedding database uses an 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:
```yaml
elements:
- name: infer
args:
model: yolov5s-face
- name: demux
- name: face-alignment
- name: infer
args:
model: arcface
- name: mux
- name: arcface-identifier
args:
database: redis
threshold: 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:
```python
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:
```python
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 use
Examples:
```python
ele = ArcFaceIdentifier("redis")
```
process
def process(meta: PipelineMetadata)
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
PipelineMetadata - The metadata to process.
Returns:
meta
PipelineMetadata - The processed metadata.
Examples:
```python
meta = ArcFaceIdentifier().process(meta)
```