Skip to content

Commit fba637a

Browse files
committed
feat: Docker images optimization
1 parent 65fbb36 commit fba637a

20 files changed

+744
-646
lines changed

.dockerignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cpu.Dockerfile
2+
gpu.Dockerfile
3+
cpu-armv7.Dockerfile

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
build/
1+
build/*
2+
!build/README.md
3+
!build/build.sh
4+
!build/get_models.sh
5+
!build/get_libs.sh
26
model/
37
models/
48
clients/

.travis/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ LOCAL_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
66
ROOT_DIR=$(dirname "$LOCAL_DIR")
77
cd "$ROOT_DIR"
88

9-
mkdir build
9+
mkdir -p build
1010
cd build
1111

1212
# Configure

CMakeLists.txt

+6-6
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,10 @@ if (USE_CAFFE)
170170
if(USE_FAISS)
171171
if (NOT USE_CPU_ONLY AND CUDA_FOUND)
172172
string(REPLACE "/include" "" CUDA_PREFIX ${CUDA_INCLUDE_DIRS})
173-
string(REPLACE "arch" "=arch" FAISS_NVCC_FLAGS ${NVCC_FLAGS_EXTRA})
174-
set(CONFIGURE_OPTS --with-cuda=${CUDA_PREFIX} --with-cuda-arch="${FAISS_NVCC_FLAGS}")
173+
if (NOT CUDA_ARCH)
174+
string(REPLACE ";" " " CUDA_ARCH "${CUDA_NVCC_FLAGS}")
175+
endif()
176+
set(CONFIGURE_OPTS --with-cuda=${CUDA_PREFIX} --with-cuda-arch=${CUDA_ARCH})
175177
add_definitions(-DUSE_GPU_FAISS)
176178
else()
177179
set(CONFIGURE_OPTS "--without-cuda")
@@ -356,7 +358,6 @@ if (USE_CAFFE2)
356358
GIT_SUBMODULES ${PYTORCH_SUBMODULES}
357359
UPDATE_DISCONNECTED 1
358360
GIT_TAG ${PYTORCH_SUPPORTED_COMMIT}
359-
GIT_CONFIG advice.detachedHead=false
360361
PATCH_COMMAND test -f ${PYTORCH_COMPLETE} && echo Skipping || echo cp modules/detectron/*_op.* caffe2/operators | bash && cp ${CAFFE2_OPS} caffe2/operators && git am ${PYTORCH_PATCHES}
361362
CONFIGURE_COMMAND test -f ${PYTORCH_COMPLETE} && echo Skipping || cmake ../pytorch ${PYTORCH_FLAGS}
362363
BUILD_COMMAND test -f ${PYTORCH_COMPLETE} && echo Skipping || make -j${N}
@@ -382,7 +383,6 @@ if (USE_CAFFE2)
382383
GIT_REPOSITORY https://github.com/facebookresearch/Detectron
383384
UPDATE_DISCONNECTED 1
384385
GIT_TAG ${DETECTRON_SUPPORTED_COMMIT}
385-
GIT_CONFIG advice.detachedHead=false
386386
PATCH_COMMAND test -f ${DETECTRON_COMPLETE} && echo Skipping || git am ${DETECTRON_PATCHES}
387387
CONFIGURE_COMMAND ""
388388
BUILD_COMMAND ""
@@ -435,7 +435,7 @@ if (USE_TF)
435435
tensorflow_cc
436436
PREFIX tensorflow_cc
437437
INSTALL_DIR ${CMAKE_BINARY_DIR}
438-
DOWNLOAD_COMMAND git clone https://github.com/FloopCZ/tensorflow_cc.git
438+
DOWNLOAD_COMMAND git clone --branch v1.15.0 https://github.com/FloopCZ/tensorflow_cc.git
439439
CONFIGURE_COMMAND cd tensorflow_cc && mkdir -p build && cd build && cmake -DTENSORFLOW_STATIC=OFF -DTENSORFLOW_SHARED=ON .. && make && ln -s ${CMAKE_BINARY_DIR}/tensorflow_cc/src/tensorflow_cc/tensorflow_cc/build/tensorflow/tensorflow/contrib/makefile/gen/protobuf ${CMAKE_BINARY_DIR}/protobuf
440440
BUILD_COMMAND ""
441441
INSTALL_COMMAND ""
@@ -447,7 +447,7 @@ if (USE_TF)
447447
tensorflow_cc
448448
PREFIX tensorflow_cc
449449
INSTALL_DIR ${CMAKE_BINARY_DIR}
450-
DOWNLOAD_COMMAND git clone https://github.com/FloopCZ/tensorflow_cc.git
450+
DOWNLOAD_COMMAND git clone --branch v1.15.0 https://github.com/FloopCZ/tensorflow_cc.git
451451
CONFIGURE_COMMAND cd tensorflow_cc && mkdir -p build && cd build && cmake -DTENSORFLOW_STATIC=OFF -DTENSORFLOW_SHARED=ON -DALLOW_CUDA=OFF .. && make && ln -s ${CMAKE_BINARY_DIR}/tensorflow_cc/src/tensorflow_cc/tensorflow_cc/build/tensorflow/tensorflow/contrib/makefile/gen/protobuf ${CMAKE_BINARY_DIR}/protobuf
452452
BUILD_COMMAND ""
453453
INSTALL_COMMAND ""

docker/README.md build/README.md

+91-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## DeepDetect Docker images
1+
# DeepDetect Docker images
22

33
This repository contains the Dockerfiles for building the CPU and GPU images for deepdetect.
44

@@ -10,7 +10,7 @@ The docker images contain:
1010

1111
This allows to run the container and set an image classification model based on deep (residual) nets in two short command line calls.
1212

13-
### Getting and running official images
13+
## Getting and running official images
1414

1515
```
1616
docker pull jolibrain/deepdetect_cpu
@@ -20,7 +20,7 @@ or
2020
docker pull jolibrain/deepdetect_gpu
2121
```
2222

23-
#### Running the CPU image
23+
### Running the CPU image
2424

2525
```
2626
docker run -d -p 8080:8080 jolibrain/deepdetect_cpu
@@ -48,7 +48,7 @@ curl -X POST "http://localhost:8080/predict" -d "{\"service\":\"imageserv\",\"pa
4848
{"status":{"code":200,"msg":"OK"},"head":{"method":"/predict","time":852.0,"service":"imageserv"},"body":{"predictions":{"uri":"http://i.ytimg.com/vi/0vxOhd4qlnA/maxresdefault.jpg","classes":[{"prob":0.2255125343799591,"cat":"n03868863 oxygen mask"},{"prob":0.20917612314224244,"cat":"n03127747 crash helmet"},{"last":true,"prob":0.07399296760559082,"cat":"n03379051 football helmet"}]}}}
4949
```
5050

51-
#### Running the GPU image
51+
### Running the GPU image
5252

5353
This requires [nvidia-docker](https://github.com/NVIDIA/nvidia-docker) in order for the local GPUs to be made accessible by the container.
5454

@@ -75,7 +75,7 @@ curl -X POST "http://localhost:8080/predict" -d "{\"service\":\"imageserv\",\"pa
7575

7676
Try the `POST` call twice: first time loads the net so it takes slightly below a second, then second call should yield a `time` around 100ms as reported in the output JSON.
7777

78-
#### Access to server logs
78+
### Access to server logs
7979

8080
To look at server logs, use
8181
```
@@ -112,10 +112,92 @@ docker run -d -p 8080:8080 -v /path/to/volume:/mnt jolibrain/deepdetect_cpu
112112
```
113113
where `path/to/volume` is the path to your local volume that you'd like to attach to `/opt/deepdetect/`. This is useful for sharing / saving models, etc...
114114

115-
#### Building an image
115+
## Build Deepdetect Docker images
116116

117-
Example goes with the CPU image:
117+
Dockerfiles are presents on project root folder.
118+
119+
We choose to prefix Dockerfiles with target architecture :
120+
* cpu-armv7.Dockerfile
121+
* cpu.Dockerfile
122+
* gpu.Dockerfile
123+
124+
### Build script
125+
126+
Build script is avaliable in docker path : build/build.sh
127+
128+
Docker build-arg : DEEPDETECT_BUILD
129+
130+
Description : DEEPDETECT_BUILD build argument change cmake arguments in build.sh script.
131+
132+
Expected values :
133+
134+
* CPU
135+
* caffe-tf
136+
* default
137+
* GPU
138+
* tf
139+
* tf-cpu
140+
* caffe-cpu-tf
141+
* caffe-tf
142+
* caffe2
143+
* p100
144+
* volta
145+
* volta-faiss
146+
* faiss
147+
* default
148+
149+
#### Launch build with environments variables
150+
151+
```bash
152+
DEEPDETECT_ARCH=cpu,gpu DEEPDETECT_BUILD=default,caffe-tf,armv7,[...] ./build.sh
153+
```
154+
155+
#### Launch build with build script parameters
156+
157+
```bash
158+
Params usage: ./build.sh [options...]
159+
160+
-a, --deepdetect-arch Choose Deepdetect architecture : cpu,gpu
161+
-b, --deepdetect-build Choose Deepdetect build profile : CPU (default,caffe-tf,armv7) / GPU (default,caffe-cpu-tf,caffe-tf,caffe2,p100,volta)
162+
```
163+
164+
### Building an image
165+
166+
#### Docker build arguments
167+
168+
* DEEPDETECT_BUILD : Change cmake arguments, checkout build script documentation.
169+
* DEEPDETECT_DEFAULT_MODELS : [**true**/false] Enable or disable default models in deepdetect docker image. Default models size is about 160MB.
170+
171+
#### Build examples
172+
173+
Example with CPU image:
118174
```
119-
cd cpu
120-
docker build -t jolibrain/deepdetect_cpu --no-cache .
175+
# Build with default cmake
176+
docker build -t jolibrain/deepdetect_cpu --no-cache -f cpu.Dockerfile .
177+
178+
# Build with default cmake and without default models
179+
docker build --build-arg DEEPDETECT_DEFAULT_MODELS=false -t jolibrain/deepdetect_cpu --no-cache -f cpu.Dockerfile .
180+
181+
# Build with custom cmake
182+
docker build --build-arg DEEPDETECT_BUILD=caffe-tf -t jolibrain/deepdetect_cpu --no-cache -f cpu.Dockerfile .
183+
121184
```
185+
186+
Example with CPU (armv7) image:
187+
```
188+
# Build with default cmake
189+
docker build -t jolibrain/deepdetect_cpu:armv7 --no-cache -f cpu-armv7.Dockerfile .
190+
191+
```
192+
193+
Example with GPU image:
194+
```
195+
# Build with default cmake
196+
docker build -t jolibrain/deepdetect_gpu --no-cache -f gpu.Dockerfile .
197+
198+
# Build with default cmake and without default models
199+
docker build --build-arg DEEPDETECT_DEFAULT_MODELS=false -t jolibrain/deepdetect_gpu --no-cache -f gpu.Dockerfile .
200+
201+
# Build with custom cmake
202+
docker build --build-arg DEEPDETECT_BUILD=caffe-tf -t jolibrain/deepdetect_gpu --no-cache -f gpu.Dockerfile .
203+
```

0 commit comments

Comments
 (0)