# 1:N FaceRecognition(Face Search) - Docker

## Overview

This project demonstrates an advanced `1:N face recognition` technology implemented via a `Dockerized Flask API`.

This demo performs `1:N face recognition`, `face search SDK` derived from `KBY-AI`'s [face recognition server SDK](https://hub.docker.com/r/kbyai/face-recognition) by implementing the functionalities to register face and search face from database(`PostgreSQL`).\
This demo offers `API`s to enroll face, to search face, to see database, to clear database. And every `API` can be customized by updating [app.py](https://github.com/kby-ai/FaceSearch-Docker/blob/main/app.py) file accordingly.

## SDK

{% content-ref url="/pages/of2yT7uMutmqK03HhwNQ" %}
[Face Search SDK(1:N Face Recognition) - Server](/help/product/face-liveness-detection-sdk-face-recognition-sdk/face-search-sdk-1-n-face-recognition-server.md)
{% endcontent-ref %}

## Github

{% embed url="<https://github.com/kby-ai/FaceSearch-Docker>" %}

## Test Online

{% embed url="<https://web.kby-ai.com/>" %}

## Postman Endpoints

To test the `API`, you can use `Postman`. Here are the [endpoints](https://github.com/kby-ai/FaceSearch-Docker/blob/main/kby-ai-facesearch.postman_collection.json) for testing:

1. `http://<your-base-url>/register`\
   This `API` enrolls face data from image base64 format and save it to database(`PostgreSQL`)<br>
2. `http://<your-base-url>/search`\
   This `API` seeks face similar to input face among database and returns enrolled image ID and similarity score.<br>
3. `http://<your-base-url>/user_list`\
   This `API` shows all data enrolled on database(`PostgreSQL`).<br>
4. `http://<your-base-url>/remove_all`\
   This `API` removes all data from database.

<figure><img src="/files/VW9WpyE0cPtfGxRNRshn" alt=""><figcaption><p>Example of face search endpoint</p></figcaption></figure>

## How to Run

### 1. System Requirements

**CPU:** `2 cores` or more (Recommended: `8 cores`)&#x20;

**RAM:** `4 GB` or more (Recommended: `8 GB`)&#x20;

**HDD:** 4 GB or more (Recommended: `8 GB`)&#x20;

**OS:** Ubuntu 20.04 or later&#x20;

**Dependency:** OpenVINO™ Runtime (Version: `2022.3`)

### 2. Setup and Test

* Clone the project:

```bash
git clone https://github.com/kby-ai/FaceSearch-Docker.git
```

* Download the model from `Google Drive`: [click here](https://drive.google.com/file/d/1ExXnc-QMVCFtGoP3xOkjoQFq56hO0PV0/view?usp=sharing)

```bash
cd FaceSearch-Docker

wget --load-cookies /tmp/cookies.txt "https://docs.google.com/uc?export=download&confirm=$(wget --quiet --save-cookies /tmp/cookies.txt --keep-session-cookies --no-check-certificate 'https://docs.google.com/uc?export=download&id=19vA7ZOlo19BcW8v4iCoCGahUEbgKCo48' -O- | sed -rn 's/.*confirm=([0-9A-Za-z_]+).*/\1\n/p')&id=19vA7ZOlo19BcW8v4iCoCGahUEbgKCo48" -O data.zip && rm -rf /tmp/cookies.txt

unzip data.zip
```

* Build the `Docker` image:

```bash
sudo docker build --pull --rm -f Dockerfile -t kby-ai-face-search:latest .
```

* Get `Machine Code`:

```bash
sudo docker run -e LICENSE="xxxxx" kby-ai-face-search:latest
```

* Send us the `machine code` obtained.

<figure><img src="/files/GxxsR5xRJe0Gw5imeRpa" alt=""><figcaption><p>How to get machine code</p></figcaption></figure>

* Update the `license.txt` file by overwriting the license key that you received from `KBY-AI` team.
* Run the `Docker` container:

```bash
sudo docker run -v ./license.txt:/root/kby-ai-face/license.txt -p 8081:8080 -p 9001:9000 kby-ai-face-search:latest
```

<figure><img src="/files/uCJdh9tfHzDE41ZgZgVt" alt=""><figcaption><p>Activation value 0 indicates that SDK has been activated successfully.</p></figcaption></figure>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.kby-ai.com/help/demo-projects/server-windows-linux/1-n-facerecognition-face-search-docker.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
