Skip to content

Commit d57cd2d

Browse files
committed
Add Dockerfile
1 parent eff6539 commit d57cd2d

File tree

3 files changed

+173
-0
lines changed

3 files changed

+173
-0
lines changed

Dockerfile

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## === Stage 1 --- Build dlib wheel ===
2+
FROM python:3.8
3+
4+
## Build 'dlib' separately - it takes a long time and needs a lot of space
5+
RUN apt-get update && apt-get install -y build-essential cmake
6+
RUN mkdir -p /tmp/dlib
7+
RUN pip wheel --use-pep517 --wheel-dir /tmp/dlib dlib
8+
RUN ln /tmp/dlib/dlib-*.whl /tmp/dlib.whl
9+
10+
11+
## === Stage 2 --- Build the actual container ===
12+
FROM python:3.8
13+
14+
WORKDIR /app
15+
EXPOSE 5000
16+
17+
# Use 'dlib.whl' from the above container
18+
COPY --from=0 /tmp/dlib /tmp/dlib
19+
RUN pip install /tmp/dlib/dlib-*.whl
20+
RUN rm -rf /tmp/dlib
21+
22+
# libGL1 is required for opencv-python
23+
RUN apt-get update && apt-get install -y libgl1 && apt-get clean
24+
25+
# Prevent re-installing if source has changed but not requirements.txt
26+
COPY requirements.txt .
27+
RUN pip install -r requirements.txt && rm -rf /root/.cache
28+
29+
# Copy all the files
30+
COPY . .
31+
RUN rm -rf .git
32+
33+
# Configure for YOLOv4
34+
RUN INSTALL_YOLOV3=no INSTALL_TINYYOLOV3=no INSTALL_YOLOV4=yes INSTALL_TINYYOLOV4=no ./get_models.sh
35+
RUN cp mlapiconfig.yolo4.ini mlapiconfig.ini
36+
37+
CMD [ "python3", "./mlapi.py", "-c", "mlapiconfig.ini" ]

mlapiconfig.yolo4.ini

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
[general]
2+
# This is an optional file
3+
# If specified, you can specify tokens with secret values in that file
4+
# and onlt refer to the tokens in your main config file
5+
6+
secrets=./secrets.ini
7+
#secrets=./secrets.mine
8+
9+
# port that mlapi will listen on. Default 5000
10+
port=5000
11+
12+
# Maximum # of processes that will be forked
13+
# to handle requests. Note that each process will
14+
# have its own copy of the model, so memory can
15+
# build up very quickly
16+
# This number also dictates how many requests will be executed in parallel
17+
# The rest will be queued
18+
19+
# For now, keep this to 1 if you are on a GPU
20+
processes=1
21+
22+
# the secret key that will be used to sign
23+
# JWT tokens. Make sure you change the value
24+
# in your secrets.ini
25+
mlapi_secret_key=!MLAPI_SECRET_KEY
26+
27+
# folder where images will be uploaded
28+
# default ./images
29+
images_path=./images
30+
31+
# folder where the user DB will be stored
32+
db_path=./db
33+
34+
# If specified, will limit detected object size to this amount of
35+
# the total image size passed. Can help avoiding weird detections
36+
# You can specify as % or px. Default is px
37+
# Remember the image is resized to 416x416 internally. better
38+
# to keep in %
39+
max_detection_size=100%
40+
41+
# You can now limit the # of detection process
42+
# per target processor. If not specified, default is 1
43+
# Other detection processes will wait to acquire lock
44+
45+
cpu_max_processes=3
46+
tpu_max_processes=1
47+
gpu_max_processes=1
48+
49+
# NEW: Time to wait in seconds per processor to be free, before
50+
# erroring out. Default is 120 (2 mins)
51+
cpu_max_lock_wait=120
52+
tpu_max_lock_wait=120
53+
gpu_max_lock_wait=120
54+
55+
56+
[object]
57+
58+
# for Yolov3
59+
#object_framework=opencv
60+
#object_processor=cpu
61+
#object_config=./models/yolov3/yolov3.cfg
62+
#object_weights=./models/yolov3/yolov3.weights
63+
#object_labels=./models/yolov3/coco.names
64+
65+
# for Tiny Yolov3
66+
#object_framework=opencv
67+
#object_processor=cpu
68+
#object_config=./models/tinyyolov3/yolov3-tiny.cfg
69+
#object_weights=./models/tinyyolov3/yolov3-tiny.weights
70+
#object_labels=./models/tinyyolov3/coco.names
71+
72+
# for Yolov4
73+
object_framework=opencv
74+
object_processor=cpu
75+
object_config=./models/yolov4/yolov4.cfg
76+
object_weights=./models/yolov4/yolov4.weights
77+
object_labels=./models/yolov4/coco.names
78+
79+
# for Tiny Yolov4
80+
#object_framework=opencv
81+
#object_processor=cpu
82+
#object_config=./models/tinyyolov4/yolov4-tiny.cfg
83+
#object_weights=./models/tinyyolov4/yolov4-tiny.weights
84+
#object_labels=./models/tinyyolov4/coco.names
85+
86+
# for Google Coral Edge TPU
87+
#object_framework=coral_edgetpu
88+
#object_processor=tpu
89+
#object_weights=./models/coral_edgetpu/ssd_mobilenet_v2_coco_quant_postprocess_edgetpu.tflite
90+
#object_labels=./models/coral_edgetpu/coco_indexed.names
91+
92+
93+
[face]
94+
face_detection_framework=dlib
95+
face_recognition_framework=dlib
96+
face_num_jitters=0
97+
face_upsample_times=1
98+
face_model=cnn
99+
face_train_model=hog
100+
face_recog_dist_threshold=0.6
101+
face_recog_knn_algo=ball_tree
102+
103+
known_images_path=./known_faces
104+
unknown_images_path=./unknown_faces
105+
106+
unknown_face_name=unknown face
107+
save_unknown_faces=yes
108+
save_unknown_faces_leeway_pixels=50
109+
110+
[alpr]
111+
112+
alpr_use_after_detection_only=yes
113+
alpr_api_type=cloud
114+
115+
# -----| If you are using plate recognizer | ------
116+
alpr_service=plate_recognizer
117+
alpr_key=!PLATEREC_ALPR_KEY
118+
platerec_stats=yes
119+
#platerec_regions=['us','cn','kr']
120+
platerec_min_dscore=0.1
121+
platerec_min_score=0.2
122+
123+
# ----| If you are using openALPR |-----
124+
#alpr_service=open_alpr
125+
#alpr_key=!OPENALPR_ALPR_KEY
126+
#openalpr_recognize_vehicle=1
127+
#openalpr_country=us
128+
#openalpr_state=ca
129+
# openalpr returns percents, but we convert to between 0 and 1
130+
#openalpr_min_confidence=0.3
131+
132+
# ----| If you are using openALPR command line |-----
133+
openalpr_cmdline_binary=alpr
134+
openalpr_cmdline_params=-j -d
135+
openalpr_cmdline_min_confidence=0.3

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ scikit_learn
1313
face_recognition
1414
pyzm>=0.1.27
1515
portalocker
16+
opencv-python>=4.3

0 commit comments

Comments
 (0)