From 4ae18ee852536332661c290ab1ca974a5ad72530 Mon Sep 17 00:00:00 2001 From: byarbrough <6315292+byarbrough@users.noreply.github.com> Date: Mon, 11 Nov 2019 11:47:56 -0500 Subject: [PATCH 1/3] Makefile for all stages Close #15 Began with dreaded cv2 not found. Having earned agony earlier in this project, I knew that the problem was most likely with running setupvars and init OpenVINO env. Log in with a shell (as root, which prompted the run_root addition) and running 'source /opt/intel/openvino/bin/setupvars.sh' allowed me to then run the classification sample. Actually, I had to unearth some dependencies first, such as libsm6, libgtk... all the ones now included in the first RUN in Dockerfile. The 'source' command in bash essentially makes variables and things set when the script is executed available to later processes. Simply calling setupvars.sh didn't solve the problem because then nothing was changed when I ran inference. However, source is not included in sh, which is Docker default. Fortunately, '.' served enough of the same purpose. I opted to switch to . instead of using SHELL in the Dockerfile to switch the default. I also added a '-l' to the CMD. This is to make sure that .bashrc gets sourced when going into an interactive shell. fatal: Invalid path '/opt/intel/openvino_2019.2.242/bin/setupvars.sh allowed me to then run the classification sample. Actually, I had to unearth some dependencies first, such as libsm6, libgtk... all the ones now included in the first RUN in Dockerfile. The source command in bash essentially makes variables and things set when the script is executed available to later processes. Simply calling setupvars.sh didn't solve the problem because then nothing was changed when I ran inference. However, source is not included in sh, which is Docker default. Fortunately, . served enough of the same purpose. I opted to switch to . instead of using SHELL in the Dockerfile to switch the default. I also added a -l to the CMD. This is to make sure that .bashrc gets sourced when going into an interactive shell. --- Dockerfile | 16 +++++++++++----- Makefile | 12 ++++++++++-- requirements.txt | 3 ++- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 99513e7..18ff1ab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,21 @@ FROM tensorflow/tensorflow:1.15.0-py3 -# this is based on https://github.com/IntelAI/OpenVINO-model-server/blob/master/Dockerfile WORKDIR /app # basic install RUN apt-get update && apt-get install -y --no-install-recommends \ ca-certificates \ + libsm6 \ + libxext6 \ + libxrender-dev \ + libgtk-3-0 \ lsb-core \ sudo +# additional python dependencies +copy requirements.txt /app +RUN pip --no-cache-dir install -r requirements.txt + # download OpenVINO RUN curl -o GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB RUN apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS-2019.PUB @@ -16,8 +23,7 @@ RUN echo "deb https://apt.repos.intel.com/openvino/2019/ all main" > /etc/apt/so # install OpenVINO RUN apt-get update && apt-get install -y intel-openvino-dev-ubuntu18-2019.3.376 RUN cd /opt/intel/openvino/deployment_tools/model_optimizer/install_prerequisites/ && ./install_prerequisites_tf.sh -RUN /opt/intel/openvino/bin/setupvars.sh -# additional python dependencies -copy requirements.txt /app -RUN pip --no-cache-dir install -r requirements.txt \ No newline at end of file +# enviornment setup +RUN echo source /opt/intel/openvino/bin/setupvars.sh >> /root/.bashrc +CMD ["/bin/bash", "-l"] \ No newline at end of file diff --git a/Makefile b/Makefile index e5d1063..c5a965d 100644 --- a/Makefile +++ b/Makefile @@ -44,11 +44,12 @@ help: @echo ' run run docker $(IMG) as $(APP) for current user: $(HOST_USER)(uid=$(HOST_UID))' @echo ' shell open interactive shell to stopped container $(APP) for current user' @echo ' stop stop $(APP)' + @echo ' start start $(APP)' @echo ' test test the model with tensorflow on data in data/test' @echo ' train train a model on data in the data/train directory' @echo '' -all: | build run train convert_32 +all: | build run train convert_32 infer build: sudo docker build -t $(IMG) . @@ -63,7 +64,8 @@ convert_32: sudo docker exec -w /app/models/openvino $(APP) python $(MO_TF) --input_model /app/models/$(MOD).pb -b $(BATCH_SIZE) --data_type FP32 --scale 255 --reverse_input_channels; infer: - sudo docker exec $(APP) python infer/classification_sample.py -m /app/models/openvino/$(MOD).xml -nt 5 -i /app/data/infer/ -d CPU + sudo docker exec $(APP) /bin/bash -c \ + ". /opt/intel/openvino/bin/setupvars.sh && python infer/classification_sample.py -m /app/models/openvino/$(MOD).xml -nt 5 -i /app/data/infer/* -d CPU" prune: sudo docker system prune -af @@ -74,9 +76,15 @@ rebuild: run: sudo docker run -u $(HOST_UID):$(HOST_GID) -it -d --mount type=bind,source=${CURDIR},destination=/app,consistency=cached --name $(APP) $(IMG); +run_root: + sudo docker run -it -d --mount type=bind,source=${CURDIR},destination=/app,consistency=cached --name $(APP) $(IMG); + shell: sudo docker start -i $(APP) +start: + sudo docker start $(APP) + stop: sudo docker stop $(APP) diff --git a/requirements.txt b/requirements.txt index ccfdcc4..6b771ee 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ networkx==2.3 Pillow -SciPy \ No newline at end of file +SciPy +opencv-python-headless \ No newline at end of file From a52102637e235f20109a9550ea8b048e71656b84 Mon Sep 17 00:00:00 2001 From: byarbrough <6315292+byarbrough@users.noreply.github.com> Date: Mon, 11 Nov 2019 12:02:01 -0500 Subject: [PATCH 2/3] add .dockerignore This reduces the size of docker context, which reduces build times. --- .dockerignore | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .dockerignore diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..4616f9d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,6 @@ +*.md +!README.md +data/* +models/* +infer/* +.git From 8fe2edf6d7965a73ab844d157d5abaf11bb83dd3 Mon Sep 17 00:00:00 2001 From: Brian <6315292+byarbrough@users.noreply.github.com> Date: Mon, 11 Nov 2019 12:07:34 -0500 Subject: [PATCH 3/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c8eb472..5632a74 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ data Makefile does not yet implement automated testing, so it is fine if `data/test` is empty. ### Run -To build the Docker image, train a model, and convert that model to a 32-bit OpenVINO format, simply call +To build the Docker image, train a model, and convert that model to a 32-bit OpenVINO format and run a sample inference on `infer/*`, simply call ``` make all ```