Skip to content

Commit

Permalink
Makefile for all stages
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
byarbrough committed Nov 11, 2019
1 parent 7fd913f commit 4ae18ee
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
16 changes: 11 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
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
RUN echo "deb https://apt.repos.intel.com/openvino/2019/ all main" > /etc/apt/sources.list.d/intel-openvino-2019.list
# 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
# enviornment setup
RUN echo source /opt/intel/openvino/bin/setupvars.sh >> /root/.bashrc
CMD ["/bin/bash", "-l"]
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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) .
Expand All @@ -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
Expand All @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
networkx==2.3
Pillow
SciPy
SciPy
opencv-python-headless

1 comment on commit 4ae18ee

@byarbrough
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also close #25

Please sign in to comment.