parent
85d42b7a32
commit
99c6b0945c
35 changed files with 1113 additions and 122 deletions
@ -0,0 +1 @@ |
|||||||
|
*.pt filter=lfs diff=lfs merge=lfs -text |
@ -0,0 +1,203 @@ |
|||||||
|
Copyright 2019 Petr Masopust, Aprar s.r.o.. All rights reserved. |
||||||
|
|
||||||
|
Apache License |
||||||
|
Version 2.0, January 2004 |
||||||
|
http://www.apache.org/licenses/ |
||||||
|
|
||||||
|
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION |
||||||
|
|
||||||
|
1. Definitions. |
||||||
|
|
||||||
|
"License" shall mean the terms and conditions for use, reproduction, |
||||||
|
and distribution as defined by Sections 1 through 9 of this document. |
||||||
|
|
||||||
|
"Licensor" shall mean the copyright owner or entity authorized by |
||||||
|
the copyright owner that is granting the License. |
||||||
|
|
||||||
|
"Legal Entity" shall mean the union of the acting entity and all |
||||||
|
other entities that control, are controlled by, or are under common |
||||||
|
control with that entity. For the purposes of this definition, |
||||||
|
"control" means (i) the power, direct or indirect, to cause the |
||||||
|
direction or management of such entity, whether by contract or |
||||||
|
otherwise, or (ii) ownership of fifty percent (50%) or more of the |
||||||
|
outstanding shares, or (iii) beneficial ownership of such entity. |
||||||
|
|
||||||
|
"You" (or "Your") shall mean an individual or Legal Entity |
||||||
|
exercising permissions granted by this License. |
||||||
|
|
||||||
|
"Source" form shall mean the preferred form for making modifications, |
||||||
|
including but not limited to software source code, documentation |
||||||
|
source, and configuration files. |
||||||
|
|
||||||
|
"Object" form shall mean any form resulting from mechanical |
||||||
|
transformation or translation of a Source form, including but |
||||||
|
not limited to compiled object code, generated documentation, |
||||||
|
and conversions to other media types. |
||||||
|
|
||||||
|
"Work" shall mean the work of authorship, whether in Source or |
||||||
|
Object form, made available under the License, as indicated by a |
||||||
|
copyright notice that is included in or attached to the work |
||||||
|
(an example is provided in the Appendix below). |
||||||
|
|
||||||
|
"Derivative Works" shall mean any work, whether in Source or Object |
||||||
|
form, that is based on (or derived from) the Work and for which the |
||||||
|
editorial revisions, annotations, elaborations, or other modifications |
||||||
|
represent, as a whole, an original work of authorship. For the purposes |
||||||
|
of this License, Derivative Works shall not include works that remain |
||||||
|
separable from, or merely link (or bind by name) to the interfaces of, |
||||||
|
the Work and Derivative Works thereof. |
||||||
|
|
||||||
|
"Contribution" shall mean any work of authorship, including |
||||||
|
the original version of the Work and any modifications or additions |
||||||
|
to that Work or Derivative Works thereof, that is intentionally |
||||||
|
submitted to Licensor for inclusion in the Work by the copyright owner |
||||||
|
or by an individual or Legal Entity authorized to submit on behalf of |
||||||
|
the copyright owner. For the purposes of this definition, "submitted" |
||||||
|
means any form of electronic, verbal, or written communication sent |
||||||
|
to the Licensor or its representatives, including but not limited to |
||||||
|
communication on electronic mailing lists, source code control systems, |
||||||
|
and issue tracking systems that are managed by, or on behalf of, the |
||||||
|
Licensor for the purpose of discussing and improving the Work, but |
||||||
|
excluding communication that is conspicuously marked or otherwise |
||||||
|
designated in writing by the copyright owner as "Not a Contribution." |
||||||
|
|
||||||
|
"Contributor" shall mean Licensor and any individual or Legal Entity |
||||||
|
on behalf of whom a Contribution has been received by Licensor and |
||||||
|
subsequently incorporated within the Work. |
||||||
|
|
||||||
|
2. Grant of Copyright License. Subject to the terms and conditions of |
||||||
|
this License, each Contributor hereby grants to You a perpetual, |
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable |
||||||
|
copyright license to reproduce, prepare Derivative Works of, |
||||||
|
publicly display, publicly perform, sublicense, and distribute the |
||||||
|
Work and such Derivative Works in Source or Object form. |
||||||
|
|
||||||
|
3. Grant of Patent License. Subject to the terms and conditions of |
||||||
|
this License, each Contributor hereby grants to You a perpetual, |
||||||
|
worldwide, non-exclusive, no-charge, royalty-free, irrevocable |
||||||
|
(except as stated in this section) patent license to make, have made, |
||||||
|
use, offer to sell, sell, import, and otherwise transfer the Work, |
||||||
|
where such license applies only to those patent claims licensable |
||||||
|
by such Contributor that are necessarily infringed by their |
||||||
|
Contribution(s) alone or by combination of their Contribution(s) |
||||||
|
with the Work to which such Contribution(s) was submitted. If You |
||||||
|
institute patent litigation against any entity (including a |
||||||
|
cross-claim or counterclaim in a lawsuit) alleging that the Work |
||||||
|
or a Contribution incorporated within the Work constitutes direct |
||||||
|
or contributory patent infringement, then any patent licenses |
||||||
|
granted to You under this License for that Work shall terminate |
||||||
|
as of the date such litigation is filed. |
||||||
|
|
||||||
|
4. Redistribution. You may reproduce and distribute copies of the |
||||||
|
Work or Derivative Works thereof in any medium, with or without |
||||||
|
modifications, and in Source or Object form, provided that You |
||||||
|
meet the following conditions: |
||||||
|
|
||||||
|
(a) You must give any other recipients of the Work or |
||||||
|
Derivative Works a copy of this License; and |
||||||
|
|
||||||
|
(b) You must cause any modified files to carry prominent notices |
||||||
|
stating that You changed the files; and |
||||||
|
|
||||||
|
(c) You must retain, in the Source form of any Derivative Works |
||||||
|
that You distribute, all copyright, patent, trademark, and |
||||||
|
attribution notices from the Source form of the Work, |
||||||
|
excluding those notices that do not pertain to any part of |
||||||
|
the Derivative Works; and |
||||||
|
|
||||||
|
(d) If the Work includes a "NOTICE" text file as part of its |
||||||
|
distribution, then any Derivative Works that You distribute must |
||||||
|
include a readable copy of the attribution notices contained |
||||||
|
within such NOTICE file, excluding those notices that do not |
||||||
|
pertain to any part of the Derivative Works, in at least one |
||||||
|
of the following places: within a NOTICE text file distributed |
||||||
|
as part of the Derivative Works; within the Source form or |
||||||
|
documentation, if provided along with the Derivative Works; or, |
||||||
|
within a display generated by the Derivative Works, if and |
||||||
|
wherever such third-party notices normally appear. The contents |
||||||
|
of the NOTICE file are for informational purposes only and |
||||||
|
do not modify the License. You may add Your own attribution |
||||||
|
notices within Derivative Works that You distribute, alongside |
||||||
|
or as an addendum to the NOTICE text from the Work, provided |
||||||
|
that such additional attribution notices cannot be construed |
||||||
|
as modifying the License. |
||||||
|
|
||||||
|
You may add Your own copyright statement to Your modifications and |
||||||
|
may provide additional or different license terms and conditions |
||||||
|
for use, reproduction, or distribution of Your modifications, or |
||||||
|
for any such Derivative Works as a whole, provided Your use, |
||||||
|
reproduction, and distribution of the Work otherwise complies with |
||||||
|
the conditions stated in this License. |
||||||
|
|
||||||
|
5. Submission of Contributions. Unless You explicitly state otherwise, |
||||||
|
any Contribution intentionally submitted for inclusion in the Work |
||||||
|
by You to the Licensor shall be under the terms and conditions of |
||||||
|
this License, without any additional terms or conditions. |
||||||
|
Notwithstanding the above, nothing herein shall supersede or modify |
||||||
|
the terms of any separate license agreement you may have executed |
||||||
|
with Licensor regarding such Contributions. |
||||||
|
|
||||||
|
6. Trademarks. This License does not grant permission to use the trade |
||||||
|
names, trademarks, service marks, or product names of the Licensor, |
||||||
|
except as required for reasonable and customary use in describing the |
||||||
|
origin of the Work and reproducing the content of the NOTICE file. |
||||||
|
|
||||||
|
7. Disclaimer of Warranty. Unless required by applicable law or |
||||||
|
agreed to in writing, Licensor provides the Work (and each |
||||||
|
Contributor provides its Contributions) on an "AS IS" BASIS, |
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or |
||||||
|
implied, including, without limitation, any warranties or conditions |
||||||
|
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A |
||||||
|
PARTICULAR PURPOSE. You are solely responsible for determining the |
||||||
|
appropriateness of using or redistributing the Work and assume any |
||||||
|
risks associated with Your exercise of permissions under this License. |
||||||
|
|
||||||
|
8. Limitation of Liability. In no event and under no legal theory, |
||||||
|
whether in tort (including negligence), contract, or otherwise, |
||||||
|
unless required by applicable law (such as deliberate and grossly |
||||||
|
negligent acts) or agreed to in writing, shall any Contributor be |
||||||
|
liable to You for damages, including any direct, indirect, special, |
||||||
|
incidental, or consequential damages of any character arising as a |
||||||
|
result of this License or out of the use or inability to use the |
||||||
|
Work (including but not limited to damages for loss of goodwill, |
||||||
|
work stoppage, computer failure or malfunction, or any and all |
||||||
|
other commercial damages or losses), even if such Contributor |
||||||
|
has been advised of the possibility of such damages. |
||||||
|
|
||||||
|
9. Accepting Warranty or Additional Liability. While redistributing |
||||||
|
the Work or Derivative Works thereof, You may choose to offer, |
||||||
|
and charge a fee for, acceptance of support, warranty, indemnity, |
||||||
|
or other liability obligations and/or rights consistent with this |
||||||
|
License. However, in accepting such obligations, You may act only |
||||||
|
on Your own behalf and on Your sole responsibility, not on behalf |
||||||
|
of any other Contributor, and only if You agree to indemnify, |
||||||
|
defend, and hold each Contributor harmless for any liability |
||||||
|
incurred by, or claims asserted against, such Contributor by reason |
||||||
|
of your accepting any such warranty or additional liability. |
||||||
|
|
||||||
|
END OF TERMS AND CONDITIONS |
||||||
|
|
||||||
|
APPENDIX: How to apply the Apache License to your work. |
||||||
|
|
||||||
|
To apply the Apache License to your work, attach the following |
||||||
|
boilerplate notice, with the fields enclosed by brackets "[]" |
||||||
|
replaced with your own identifying information. (Don't include |
||||||
|
the brackets!) The text should be enclosed in the appropriate |
||||||
|
comment syntax for the file format. We also recommend that a |
||||||
|
file or class name and description of purpose be included on the |
||||||
|
same "printed page" as the copyright notice for easier |
||||||
|
identification within third-party archives. |
||||||
|
|
||||||
|
Copyright [yyyy] [name of copyright owner] |
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
you may not use this file except in compliance with the License. |
||||||
|
You may obtain a copy of the License at |
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0 |
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software |
||||||
|
distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
See the License for the specific language governing permissions and |
||||||
|
limitations under the License. |
@ -0,0 +1,87 @@ |
|||||||
|
# Face recognition technology demo |
||||||
|
|
||||||
|
Mass faces identification and recognition in images. |
||||||
|
|
||||||
|
## Installation |
||||||
|
|
||||||
|
The simplest complete installation is docker compose: ``docker-compose up -d`` in root directory. For detailed installation instructions look at [API server](apiserver/README.md) or [vectorizer](vectorizer/README.md) readme files. |
||||||
|
Without nvidia docker support docker runs only on cpu with **very** degraded performance (over minute on 6 cpu cores). |
||||||
|
|
||||||
|
## Usage |
||||||
|
|
||||||
|
### Learn people faces |
||||||
|
|
||||||
|
```shell script |
||||||
|
curl -X POST -F 'person=PID' -F 'directory=DIR' -F 'file=@portrait.jpg' http://localhost:8080/learn |
||||||
|
``` |
||||||
|
|
||||||
|
Replace PID with person's id (e.g. database id or name) and DIR with your directory name (e.g. company name). People are recognized only within same directory. png or jpeg images are supported. Only images with one face are allowed for learning ! |
||||||
|
Usually only one good portrait photo is enough but you can learn more photos for each person. |
||||||
|
|
||||||
|
### Recognize people |
||||||
|
|
||||||
|
```shell script |
||||||
|
curl -X POST -F 'directory=DIR' -F 'file=@photo.jpg' http://localhost:8080/recognize |
||||||
|
``` |
||||||
|
|
||||||
|
Replace DIR with your directory name (e.g. company name). People are recognized only within same directory. For each detected face the most probable person's id is returned. png or jpeg images are supported. |
||||||
|
|
||||||
|
Example result: |
||||||
|
|
||||||
|
```json |
||||||
|
{ |
||||||
|
"status":"OK", |
||||||
|
"url":"/files/00636b47-e6a5-4fab-8a02-9e44d052c193.jpg", |
||||||
|
"filename":"photo.jpg", |
||||||
|
"directory":"mydir", |
||||||
|
"persons":[ |
||||||
|
{"id":"PID1","box":[2797,1164,2918,1285],"score":0.999998927116394,"probability":0.8342}, |
||||||
|
{"id":"PID2","box":[2398,1854,2590,2046],"score":0.9999780654907227,"probability":0.32546}, |
||||||
|
{"id":"PID3","box":[1753,1148,1905,1300],"score":0.9999217987060547,"probability":0.65785} |
||||||
|
]} |
||||||
|
``` |
||||||
|
|
||||||
|
| Field | Description | |
||||||
|
| --- | --- | |
||||||
|
| status | Status message - either OK or error text | |
||||||
|
| url | Relative url to original image | |
||||||
|
| filename | Original image filename | |
||||||
|
| directory | Directory name | |
||||||
|
| persons | Recognized people array | |
||||||
|
| id | Person's id | |
||||||
|
| box | Box around face | |
||||||
|
| score | Face detection score (i.e. probability) | |
||||||
|
| probability | Person recognition probability | |
||||||
|
|
||||||
|
## Architecture |
||||||
|
|
||||||
|
This demo consist of three parts - API server, vectorizer and database. API server is frontend server written in golang. |
||||||
|
Vectorizer is the main part which identifies faces and creates vectors from faces. Database is simple storage for learned vectors. |
||||||
|
Both API server and vectorizer are fully scalable e.g. in kubernetes. The only non scalable part is postgresql database but it can be easily replaced with different storage - e.g. HBase. |
||||||
|
Just reimplement storage.go in API server. |
||||||
|
Only API server listen to customer requests, the rest are internal components and should not be directly accessible from internet. |
||||||
|
|
||||||
|
## Future roadmap |
||||||
|
|
||||||
|
* Training on identified faces (both nets are trained separately now) |
||||||
|
* Face alignment between identification and recognition |
||||||
|
* Web user interface (help needed !) |
||||||
|
|
||||||
|
## Based on |
||||||
|
|
||||||
|
Github repositories: |
||||||
|
|
||||||
|
* [https://github.com/rainofmine/Face_Attention_Network](https://github.com/rainofmine/Face_Attention_Network) |
||||||
|
* [https://github.com/ronghuaiyang/arcface-pytorch](https://github.com/ronghuaiyang/arcface-pytorch) |
||||||
|
|
||||||
|
Papers: |
||||||
|
|
||||||
|
* [Face Attention Network: An Effective Face Detector for the Occluded Faces](https://arxiv.org/abs/1711.07246) |
||||||
|
* [AdaCos: Adaptively Scaling Cosine Logits for Effectively Learning Deep Face Representations](https://arxiv.org/abs/1905.00292) |
||||||
|
* [ArcFace: Additive Angular Margin Loss for Deep Face Recognition](https://arxiv.org/abs/1801.07698) |
||||||
|
* [SphereFace: Deep Hypersphere Embedding for Face Recognition](https://arxiv.org/abs/1704.08063) |
||||||
|
* [CosFace: Large Margin Cosine Loss for Deep Face Recognition](https://arxiv.org/abs/1801.09414) |
||||||
|
|
||||||
|
## Licensing |
||||||
|
|
||||||
|
Code in this repository is licensed under the Apache 2.0. See [LICENSE](LICENSE). |
@ -0,0 +1,20 @@ |
|||||||
|
FROM golang:alpine AS build-env |
||||||
|
|
||||||
|
RUN apk update && apk upgrade && \ |
||||||
|
apk add --no-cache bash git openssh |
||||||
|
|
||||||
|
COPY ./apiserver /apiserver/apiserver |
||||||
|
COPY ./apiserver.yaml /apiserver/apiserver.yaml |
||||||
|
COPY ./go.mod /apiserver/go.mod |
||||||
|
COPY ./main.go /apiserver/main.go |
||||||
|
|
||||||
|
WORKDIR /apiserver |
||||||
|
RUN go build -o goapp |
||||||
|
|
||||||
|
# final stage |
||||||
|
FROM alpine |
||||||
|
WORKDIR /apiserver |
||||||
|
COPY --from=build-env /apiserver/goapp /apiserver/apiserver |
||||||
|
COPY --from=build-env /apiserver/apiserver.yaml /apiserver/apiserver.yaml |
||||||
|
RUN mkdir /apiserver/files |
||||||
|
ENTRYPOINT /apiserver/apiserver |
@ -0,0 +1,129 @@ |
|||||||
|
# API server |
||||||
|
|
||||||
|
Frontend server written in golang. **Technology demo - do not use in production !** |
||||||
|
|
||||||
|
**Main purpose:** |
||||||
|
* serve stored images |
||||||
|
* send images to vectorizer |
||||||
|
* store vectors in database |
||||||
|
* compare vectors and return ids |
||||||
|
|
||||||
|
No local state, can be scaled. |
||||||
|
|
||||||
|
## Configuration |
||||||
|
Edit ``apiserver.yaml`` file: |
||||||
|
|
||||||
|
| Key | Value | Description | |
||||||
|
| --- | --- | --- | |
||||||
|
| port | 8080 | Port to listen | |
||||||
|
| vectorizer | http://vectorizer:8080/vectorize | Vectorizer url | |
||||||
|
| dbuser | faceserver | DB user | |
||||||
|
| dbpassword | secret | DB password | |
||||||
|
| dbname | faceserver | DB name | |
||||||
|
| dbhost | db | DB host | |
||||||
|
|
||||||
|
Do not change configuration if you want run prepared docker-compose. |
||||||
|
|
||||||
|
### DB configuration |
||||||
|
Only postgresql is supported now. Create new role and user: |
||||||
|
```shell script |
||||||
|
createuser -D -P -S faceserver |
||||||
|
createdb -E UTF8 -O faceserver faceserver |
||||||
|
``` |
||||||
|
|
||||||
|
Create API server tables: |
||||||
|
|
||||||
|
```shell script |
||||||
|
psql -U faceserver -h localhost faceserver <../init.sql |
||||||
|
``` |
||||||
|
|
||||||
|
## Instalation |
||||||
|
### Docker image |
||||||
|
Build docker image - preferred method: |
||||||
|
|
||||||
|
```shell script |
||||||
|
docker build -t apiserver:latest . |
||||||
|
``` |
||||||
|
|
||||||
|
### Local compilation |
||||||
|
Golang 1.12 is required. Run: |
||||||
|
|
||||||
|
```shell script |
||||||
|
go build main.go |
||||||
|
``` |
||||||
|
|
||||||
|
## HTTP API |
||||||
|
### Learn |
||||||
|
|
||||||
|
```shell script |
||||||
|
curl -X POST -F 'person=PID' -F 'directory=DIR' -F 'file=@portrait.jpg' http://localhost:8080/learn |
||||||
|
``` |
||||||
|
|
||||||
|
Replace PID with person's id (e.g. database id or name) and DIR with your directory name (e.g. company name). People are recognized only within same directory. png or jpeg images are supported. Only images with one face are allowed for learning ! |
||||||
|
|
||||||
|
Result: |
||||||
|
|
||||||
|
```json |
||||||
|
{ |
||||||
|
"status":"OK", |
||||||
|
"url":"/files/01e66d8f-536e-4e5ab3b1-521672739d15.jpg", |
||||||
|
"filename":"photo.jpg", |
||||||
|
"directory":"mydir", |
||||||
|
"persons":[ |
||||||
|
{"id":"PID","box":[0,15,65,88],"score":0.9909800887107849} |
||||||
|
]} |
||||||
|
``` |
||||||
|
|
||||||
|
|Field|Description| |
||||||
|
|--|--| |
||||||
|
|status|Status message - either OK or error text| |
||||||
|
|url|Relative url to original image| |
||||||
|
|filename|Original image filename| |
||||||
|
|directory|Directory name| |
||||||
|
|persons|Recognized people array| |
||||||
|
|id|Person's id| |
||||||
|
|box|Box around face| |
||||||
|
|score|Face detection score (i.e. probability)| |
||||||
|
|
||||||
|
### Recognize |
||||||
|
|
||||||
|
```shell script |
||||||
|
curl -X POST -F 'directory=DIR' -F 'file=@photo.jpg' http://localhost:8080/recognize |
||||||
|
``` |
||||||
|
|
||||||
|
Replace DIR with your directory name (e.g. company name). People are recognized only within same directory. For each detected face the most probable person's id is returned. png or jpeg images are supported. |
||||||
|
|
||||||
|
Result: |
||||||
|
|
||||||
|
```json |
||||||
|
{ |
||||||
|
"status":"OK", |
||||||
|
"url":"/files/00636b47-e6a5-4fab-8a02-9e44d052c193.jpg", |
||||||
|
"filename":"photo.jpg", |
||||||
|
"directory":"mydir", |
||||||
|
"persons":[ |
||||||
|
{"id":"PID1","box":[2797,1164,2918,1285],"score":0.999998927116394,"probability":0.8342}, |
||||||
|
{"id":"PID2","box":[2398,1854,2590,2046],"score":0.9999780654907227,"probability":0.32546}, |
||||||
|
{"id":"PID3","box":[1753,1148,1905,1300],"score":0.9999217987060547,"probability":0.65785} |
||||||
|
]} |
||||||
|
``` |
||||||
|
|
||||||
|
| Field | Description | |
||||||
|
| --- | --- | |
||||||
|
| status | Status message - either OK or error text | |
||||||
|
| url | Relative url to original image | |
||||||
|
| filename | Original image filename | |
||||||
|
| directory | Directory name | |
||||||
|
| persons | Recognized people array | |
||||||
|
| id | Person's id | |
||||||
|
| box | Box around face | |
||||||
|
| score | Face detection score (i.e. probability) | |
||||||
|
| probability | Person recognition probability | |
||||||
|
|
||||||
|
### Files |
||||||
|
|
||||||
|
``/files/...`` path contains all learned or recognized images. |
||||||
|
|
||||||
|
## Licensing |
||||||
|
|
||||||
|
Code in this repository is licensed under the Apache 2.0. See [LICENSE](../LICENSE). |
@ -1,8 +1,6 @@ |
|||||||
port: 8081 |
port: 8080 |
||||||
vectorizer: |
vectorizer: http://vectorizer:8080/vectorize |
||||||
url: http://localhost:8080/vectorize |
dbuser: faceserver |
||||||
db: |
dbpassword: secret |
||||||
user: faceserver |
dbname: faceserver |
||||||
password: aaa |
dbhost: db |
||||||
name: faceserver |
|
||||||
host: localhost |
|
||||||
|
@ -0,0 +1,26 @@ |
|||||||
|
version: "3.7" |
||||||
|
services: |
||||||
|
apiserver: |
||||||
|
build: |
||||||
|
context: ./apiserver |
||||||
|
ports: |
||||||
|
- "8080:8080" |
||||||
|
depends_on: |
||||||
|
- db |
||||||
|
- vectorizer |
||||||
|
vectorizer: |
||||||
|
build: |
||||||
|
context: ./vectorizer |
||||||
|
environment: |
||||||
|
VS_PORT: 8080 |
||||||
|
VS_FAN_MODEL: "./ckpt/wider6_10.pt" |
||||||
|
VS_REC_DEPTH: 50 |
||||||
|
VS_REC_MODEL: "./ckpt/recongition3_37.pt" |
||||||
|
db: |
||||||
|
image: postgres:11-alpine |
||||||
|
environment: |
||||||
|
POSTGRES_PASSWORD: secret |
||||||
|
POSTGRES_USER: faceserver |
||||||
|
POSTGRES_DB: faceserver |
||||||
|
volumes: |
||||||
|
- ./init.sql:/docker-entrypoint-initdb.d/init.sql |
@ -0,0 +1,11 @@ |
|||||||
|
CREATE TABLE persons ( |
||||||
|
id character varying(255) NOT NULL, |
||||||
|
directory character varying(255) NOT NULL, |
||||||
|
vector double precision[] NOT NULL, |
||||||
|
filename character varying(255) NOT NULL, |
||||||
|
filenameuid character varying(255) NOT NULL, |
||||||
|
box integer[] NOT NULL, |
||||||
|
score double precision NOT NULL |
||||||
|
); |
||||||
|
|
||||||
|
CREATE INDEX persons_directory ON persons USING btree (directory); |
@ -0,0 +1,160 @@ |
|||||||
|
# Vectorizer |
||||||
|
|
||||||
|
Heart of faceserver app. **Technology demo - do not use in production !** |
||||||
|
|
||||||
|
**Main purpose:** |
||||||
|
* find faces in image |
||||||
|
* create vector from face |
||||||
|
|
||||||
|
No local state, can be scaled. GPU is **highly** recommended. |
||||||
|
|
||||||
|
## Configuration |
||||||
|
|
||||||
|
Set environment variables: |
||||||
|
|
||||||
|
| Key | Default value | Description | |
||||||
|
| --- | --- | --- | |
||||||
|
| VS_PORT | 8080 | Port to listen (for Flask) | |
||||||
|
| VS_FAN_MODEL | | Path to identification model | |
||||||
|
| VS_REC_DEPTH | 50 | Recognition net depth | |
||||||
|
| VS_REC_MODEL | | Path to recognition model | |
||||||
|
|
||||||
|
Do not change configuration if you want run prepared docker-compose. |
||||||
|
|
||||||
|
## Instalation |
||||||
|
|
||||||
|
### Docker image |
||||||
|
|
||||||
|
Build docker image - preferred method if you have nvidia-docker: |
||||||
|
```shell script |
||||||
|
docker build -t vectorizer:latest . |
||||||
|
``` |
||||||
|
|
||||||
|
### Local installation |
||||||
|
|
||||||
|
Install PIP dependencies (virtualenv recommended): |
||||||
|
|
||||||
|
```shell script |
||||||
|
pip install --upgrade -r requirements.txt |
||||||
|
``` |
||||||
|
|
||||||
|
And then run server: |
||||||
|
|
||||||
|
```shell script |
||||||
|
python3 -m vectorizer.server |
||||||
|
``` |
||||||
|
|
||||||
|
## HTTP API |
||||||
|
|
||||||
|
### Vectorization |
||||||
|
|
||||||
|
```shell script |
||||||
|
curl -X POST -F 'file=@image.jpg' http://localhost:8080/vectorize |
||||||
|
``` |
||||||
|
|
||||||
|
png or jpeg images are supported. |
||||||
|
|
||||||
|
Result: |
||||||
|
|
||||||
|
```json |
||||||
|
[ |
||||||
|
{"box":[0,15,65,88],"vector":[-0.14234,...,0.32432],"score":0.9909800887107849} |
||||||
|
] |
||||||
|
``` |
||||||
|
|
||||||
|
| Field | Description | |
||||||
|
| --- | --- | |
||||||
|
| box | Box around face | |
||||||
|
| vector | Array of 512 floats | |
||||||
|
| score | Face detection score (i.e. probability) | |
||||||
|
|
||||||
|
## Training |
||||||
|
|
||||||
|
**GPU is mandatory for training !** |
||||||
|
Training takes at least several days to achieve reasonable accuracy on single RTX 2070. |
||||||
|
Trained models are stored in ``ckpt`` directory. Pretrained models with example parameters are included. |
||||||
|
|
||||||
|
### Identification |
||||||
|
|
||||||
|
Example: |
||||||
|
|
||||||
|
```shell script |
||||||
|
python3 -m identification.train --wider_train ~/datasets/wider/wider_face_train_bbx_gt.txt \ |
||||||
|
--wider_train_prefix ~/datasets/wider/WIDER_train/images \ |
||||||
|
--wider_val ~/datasets/wider/wider_face_val_bbx_gt.txt \ |
||||||
|
--wider_val_prefix ~/datasets/wider/WIDER_val/images \ |
||||||
|
--depth 50 --epochs 30 --batch_size 1 --model_name wider1 |
||||||
|
``` |
||||||
|
|
||||||
|
| Argument | Description | Required / Default value | |
||||||
|
| --- | --- | --- | |
||||||
|
| --wider_train | Path to file containing WIDER training annotations (wider_face_train_bbx_gt.txt) | Yes | |
||||||
|
| --wider_val | Path to file containing WIDER validation annotations (wider_face_val_bbx_gt.txt) | | |
||||||
|
| --wider_train_prefix | Prefix path to WIDER train images | Yes | |
||||||
|
| --wider_val_prefix | Prefix path to WIDER validation images | | |
||||||
|
| --depth | Resnet depth, must be one of 18, 34, 50, 101, 152 | 50 | |
||||||
|
| --epochs | Number of epochs | 50 | |
||||||
|
| --batch_size | Batch size - increase only if you have enough GPU memory (i.e. >16 GB) ! | 2 | |
||||||
|
| --model_name | Model name prefix | Yes | |
||||||
|
| --parallel | Run training with DataParallel | false | |
||||||
|
| --pretrained | Pretrained model (e.g. for crash recovery) | | |
||||||
|
|
||||||
|
There is also option to train from csv files - see train.py and dataloader.py for details. |
||||||
|
|
||||||
|
### Recognition |
||||||
|
|
||||||
|
Example: |
||||||
|
|
||||||
|
```shell script |
||||||
|
python3 -m recognition.train \ |
||||||
|
--casia_list ~/datasets/CASIA-maxpy-clean/train.txt \ |
||||||
|
--casia_root ~/datasets/CASIA-maxpy-clean \ |
||||||
|
--lfw_root ~/datasets/lfw \ |
||||||
|
--lfw_pair_list lfw_test_pair.txt \ |
||||||
|
--model_name recongition1 --batch_size 20 \ |
||||||
|
--loss adacos --print_freq 20 --depth 50 |
||||||
|
``` |
||||||
|
|
||||||
|
| Argument | Description | Required / Default value | |
||||||
|
| --- | --- | --- | |
||||||
|
| --casia_list | Path to CASIA dataset file list (train.txt) | Yes | |
||||||
|
| --casia_root | Path to CASIA images | Yes | |
||||||
|
| --lfw_root | Path to LFW dataset | Yes | |
||||||
|
| --lfw_pair_list | Path to LFW pair list file (lfw_test_pair.txt - in this repository) | Yes | |
||||||
|
| --depth | Resnet depth, must be one of 18, 34, 50, 101, 152 or 20 for sphere net | 50 | |
||||||
|
| --epochs | Number of epochs | 50 | |
||||||
|
| --batch_size | Batch size | 16 | |
||||||
|
| --model_name | Model name prefix | Yes | |
||||||
|
| --parallel | Run training with DataParallel | false | |
||||||
|
| --loss | One of focal_loss. cross_entropy, arcface, cosface, sphereface, adacos | cross_entropy | |
||||||
|
| --optimizer | One of sgd, adam | sgd | |
||||||
|
| --weight_decay | Weight decay | 0.0005 | |
||||||
|
| --lr | Learning rate | 0.1 | |
||||||
|
| --lr_step | Learning rate step | 10 | |
||||||
|
| --easy_margin | Use easy margin | false | |
||||||
|
| --print_freq | Print every N batch | 100 | |
||||||
|
|
||||||
|
## Datasets for training |
||||||
|
|
||||||
|
* [WIDER](http://shuoyang1213.me/WIDERFACE/) |
||||||
|
* [LFW](http://vis-www.cs.umass.edu/lfw/) |
||||||
|
* CASIA maxpy clean - no official web but can be downloaded from suspicious sites (use google) |
||||||
|
|
||||||
|
## Based on |
||||||
|
|
||||||
|
Github repositories: |
||||||
|
|
||||||
|
* [https://github.com/rainofmine/Face_Attention_Network](https://github.com/rainofmine/Face_Attention_Network) |
||||||
|
* [https://github.com/ronghuaiyang/arcface-pytorch](https://github.com/ronghuaiyang/arcface-pytorch) |
||||||
|
|
||||||
|
Papers: |
||||||
|
|
||||||
|
* [Face Attention Network: An Effective Face Detector for the Occluded Faces](https://arxiv.org/abs/1711.07246) |
||||||
|
* [AdaCos: Adaptively Scaling Cosine Logits for Effectively Learning Deep Face Representations](https://arxiv.org/abs/1905.00292) |
||||||
|
* [ArcFace: Additive Angular Margin Loss for Deep Face Recognition](https://arxiv.org/abs/1801.07698) |
||||||
|
* [SphereFace: Deep Hypersphere Embedding for Face Recognition](https://arxiv.org/abs/1704.08063) |
||||||
|
* [CosFace: Large Margin Cosine Loss for Deep Face Recognition](https://arxiv.org/abs/1801.09414) |
||||||
|
|
||||||
|
## Licensing |
||||||
|
|
||||||
|
Code in this repository is licensed under the Apache 2.0. See [LICENSE](../LICENSE). |
@ -0,0 +1,3 @@ |
|||||||
|
version https://git-lfs.github.com/spec/v1 |
||||||
|
oid sha256:60c4b6850c06c00b086e0e3918e089f6bb181f0330a9ce1b60ac184e5b09c6e0 |
||||||
|
size 98498540 |
@ -0,0 +1,3 @@ |
|||||||
|
version https://git-lfs.github.com/spec/v1 |
||||||
|
oid sha256:d0c8b9095c6b85905e7236b253db4c445113ee5fccc272e558d65d52ab4c7523 |
||||||
|
size 155109396 |
@ -0,0 +1,3 @@ |
|||||||
|
python3 -m identification.train --wider_train ~/datasets/wider/wider_face_train_bbx_gt.txt --wider_train_prefix ~/datasets/wider/WIDER_train/images \ |
||||||
|
--wider_val ~/datasets/wider/wider_face_val_bbx_gt.txt --wider_val_prefix ~/datasets/wider/WIDER_val/images \ |
||||||
|
--depth 50 --epochs 30 --batch_size 1 --model_name wider1 |
@ -1,2 +1,2 @@ |
|||||||
python3 -m recognition.train --casia_list /home/ehp/tmp/datasets/CASIA-maxpy-clean/train.txt --casia_root /home/ehp/tmp/datasets/CASIA-maxpy-clean --lfw_root /home/ehp/tmp/datasets/lfw \ |
python3 -m recognition.train --casia_list ~/datasets/CASIA-maxpy-clean/train.txt --casia_root ~/datasets/CASIA-maxpy-clean --lfw_root ~/datasets/lfw \ |
||||||
--lfw_pair_list /home/ehp/git/arcface/lfw_test_pair.txt --model_name recongition3 --batch_size 20 --loss adacos --print_freq 20 --depth 50 |
--lfw_pair_list lfw_test_pair.txt --model_name recongition1 --batch_size 20 --loss adacos --print_freq 20 --depth 50 |
||||||
|
@ -1,7 +0,0 @@ |
|||||||
#python3 -m identification.train --wider_train /home/ehp/tmp/datasets/wider/sample.txt --wider_train_prefix /home/ehp/tmp/datasets/wider/sample/images \ |
|
||||||
#--wider_val /home/ehp/tmp/datasets/wider/sample_val.txt --wider_val_prefix /home/ehp/tmp/datasets/wider/sample_val/images \ |
|
||||||
#--depth 50 --epochs 30 --batch_size 1 --model_name wider_sample1 |
|
||||||
|
|
||||||
python3 -m identification.train --wider_train /home/ehp/tmp/datasets/wider/wider_face_train_bbx_gt.txt --wider_train_prefix /home/ehp/tmp/datasets/wider/WIDER_train/images \ |
|
||||||
--wider_val /home/ehp/tmp/datasets/wider/wider_face_val_bbx_gt.txt --wider_val_prefix /home/ehp/tmp/datasets/wider/WIDER_val/images \ |
|
||||||
--depth 50 --epochs 30 --batch_size 1 --model_name widernew1 |
|
Loading…
Reference in new issue