face_verification.db package

Submodules

face_verification.db.db module

Contains the code related for face recogniction/verification using on a database.

class face_verification.db.db.Database(path)[source]

Bases: object

A simple wrapper for sqlite database

create(table_name='tt') → None[source]

Create a new table. The table name itself is not very important since we are not doing any relational searches.

Parameters

table_name (str, optional) – Defaults to “tt”.

Returns

None

delete(name: str) → None[source]

Deletes the matching name from the database

Parameters

name (str) – name to match

drop_table(table: str) → None[source]

Drops the table

Parameters

table (str) – Name of the table.

get_value(name: str) → bytes[source]

Returns the embedding associated with the name.

Parameters

name (str) – Name of the person in the database.

Returns

Bytes type embedding.

Return type

bytes

insert(name: str, value: bytes, log: bool = False)[source]

Inserts values into the database.

Parameters
  • name (str) – Name of the person.

  • value (bytes) – 512 dimensional embeddings as bytes.

  • log (bool, optional) – Logs to console. Defaults to False.

update(name: str, value: bytes) → None[source]

Updates the embedding associated with the name.

Parameters
  • name (str) – Name of the person in the database.

  • value (bytes) – Embedding as bytes

face_verification.db.db.compare_embedding(embedding: Union[torch.Tensor, numpy.ndarray], db: face_verification.db.db.Database) → Optional[Tuple[str, float]][source]
Compares the given embedding with every embedding in db. Returns the first

matched name and distance if any is found.

Parameters
  • embedding (Union[torch.Tensor, np.ndarray]) – Embedding vector, either numpy or torch

  • db (Database) – Database to search the images

Returns

Name, distance pair if matched.

Return type

Union[Tuple[str, float], None]

face_verification.db.db.load_array(byte: bytes) → numpy.ndarray[source]

Loads the given bytes array in a ndarray

Parameters

byte (bytes) – Bytes array

Returns

Numpy array.

Return type

np.ndarray

face_verification.db.db.torch_to_np(array: torch.Tensor) → numpy.ndarray[source]
Coverts torch tensor to numpy array, handles the case when torch tensor is

stuck in cuda.

Parameters

array (torch.Tensor) – Pytorch Tensor

Returns

np.ndarray

Module contents