Skip to content

Commit

Permalink
EFRS-906 Setup compreface-core configuration (#291)
Browse files Browse the repository at this point in the history
  • Loading branch information
z268 authored Dec 16, 2020
1 parent 3de6b82 commit 736f722
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 15 deletions.
4 changes: 2 additions & 2 deletions dev/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ services:

compreface-core:
image: ${registry}compreface-core:${CORE_VERSION}
build:
context: ../embedding-calculator
container_name: "compreface-core"
ports:
- "3300:3000"
build:
context: ../embedding-calculator
environment:
- ML_PORT=3000
24 changes: 15 additions & 9 deletions embedding-calculator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
ARG BASE_IMAGE=python:3.7-slim
FROM $BASE_IMAGE
ARG GPU_IDX
ARG BASE_IMAGE=${GPU_IDX:+exadel/compreface-core-cuda:101-py37}
FROM ${BASE_IMAGE:-python:3.7-slim}

RUN apt-get update && apt-get install -y build-essential cmake git wget unzip \
curl yasm pkg-config libswscale-dev libtbb2 libtbb-dev libjpeg-dev \
Expand All @@ -25,21 +26,26 @@ ENV PYTHONUNBUFFERED=0
ENV JOBLIB_MULTIPROCESSING=0

# download ML models
ARG DETECTION_MODEL="retinaface_r50_v1"
ARG CALCULATION_MODEL="arcface_r100_v1"
ENV DETECTION_MODEL=$DETECTION_MODEL CALCULATION_MODEL=$CALCULATION_MODEL
ARG DETECTION_MODEL
ARG CALCULATION_MODEL
ENV DETECTION_MODEL=${DETECTION_MODEL:-retinaface_r50_v1}
ENV CALCULATION_MODEL=${CALCULATION_MODEL:-arcface_r100_v1}
COPY srcext srcext
COPY pytest.ini .
COPY *.sh ./
RUN chmod +x *.sh
RUN ./prepare_scanners.sh

# install InsightFace packages
ARG MXNET
ARG GPU_ID
ENV GPU_ID=$GPU_ID
ARG INTEL_OPTIMIZATION
ARG GPU_IDX
ENV GPU_IDX=$GPU_IDX
ENV MXNET_MOD=${GPU_IDX:+cu101}${INTEL_OPTIMIZATION:+mkl}
ENV MXNET_LIB=mxnet${MXNET_MOD:+-$MXNET_MOD}
ENV MXNET_VER="<1.7"

RUN if [[ "$SCANNER" == "InsightFace" ]]; then \
pip --no-cache-dir install ${MXNET:-mxnet-mkl==1.6.0} -e srcext/insightface/python-package; \
pip --no-cache-dir install "$MXNET_LIB$MXNET_VER" -e srcext/insightface/python-package; \
fi

# copy rest of the code
Expand Down
28 changes: 26 additions & 2 deletions embedding-calculator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,23 @@ $ python -m src.app
```

### Docker

##### Images on DockerHub

There are some pre-build images on https://hub.docker.com/r/exadel/compreface-core. To use it run:
```
$ docker run -p 3000:3000 exadel/compreface-core:latest
```

###### DockerHub tags

| Tag | Scanner | Build arguments | Comment |
|------------------------|-------------|-------------------------------|-------------------------------|
| :0.4.0 :latest | Facenet2018 | | |
| :0.4.0-insightface | InsightFace | SCANNER=InsightFace | |
| :0.4.0-insightface-gpu | InsightFace | SCANNER=InsightFace GPU_IDX=0 | GPU_IDX - index of GPU-device |


##### Build
Builds container (also runs main tests during the build):
```
Expand All @@ -35,7 +52,7 @@ $ docker build -t embedding-calculator --build-arg SKIP_TESTS=true .

##### Run
```
$ docker run -p3000:3000 embedding-calculator
$ docker run -p 3000:3000 embedding-calculator
```

### Run tests
Expand Down Expand Up @@ -84,7 +101,14 @@ Check more models in [Model Zoo](https://github.com/deepinsight/insightface/wiki
Build container with CUDA 10.1.
```
$ docker build -t cuda101-py37 -f gpu.Dockerfile .
$ docker build -t embedding-calculator-gpu --build-arg SCANNER=InsightFace --build-arg BASE_IMAGE=cuda101-py37 --build-arg GPU_ID=0 .
$ docker build -t embedding-calculator-gpu --build-arg SCANNER=InsightFace --build-arg GPU_IDX=0 .
```

Install the nvidia-docker2 package and dependencies:
```
sudo apt-get update
sudo apt-get install -y nvidia-docker2
sudo systemctl restart docker
```

Run with enabled gpu
Expand Down
2 changes: 1 addition & 1 deletion embedding-calculator/src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class ENV(Constants):
IS_DEV_ENV = get_env('FLASK_ENV', 'production') == 'development'
BUILD_VERSION = get_env('APP_VERSION_STRING', 'dev')

GPU_ID = int(get_env('GPU_ID', '-1'))
GPU_IDX = int(get_env('GPU_IDX', '-1'))
DETECTION_MODEL = get_env('DETECTION_MODEL', 'retinaface_r50_v1')
CALCULATION_MODEL = get_env('CALCULATION_MODEL', 'arcface_r100_v1')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class InsightFace(FaceScanner):
CALCULATION_MODEL_NAME = ENV.CALCULATION_MODEL
IMG_LENGTH_LIMIT = ENV.IMG_LENGTH_LIMIT

_CTX_ID = ENV.GPU_ID
_CTX_ID = ENV.GPU_IDX
# detection settings
_NMS = 0.4
det_prob_threshold = 0.8
Expand Down

0 comments on commit 736f722

Please sign in to comment.