Search code examples
dockeropenvino

Use openvino from docker


I am trying to use OpenVINO from docker container. I use docker file from official web site https://docs.openvinotoolkit.org/latest/_docs_install_guides_installing_openvino_docker_linux.html

FROM ubuntu:18.04
USER root
WORKDIR /
SHELL ["/bin/bash", "-xo", "pipefail", "-c"]
# Creating user openvino
RUN useradd -ms /bin/bash openvino && \
    chown openvino -R /home/openvino
ARG DEPENDENCIES="autoconf \
                  automake \
                  build-essential \
                  cmake \
                  cpio \
                  curl \
                  gnupg2 \
                  libdrm2 \
                  libglib2.0-0 \
                  lsb-release \
                  libgtk-3-0 \
                  libtool \
                  udev \
                  unzip \
                  dos2unix"
RUN apt-get update && \
    apt-get install -y --no-install-recommends ${DEPENDENCIES} && \
    rm -rf /var/lib/apt/lists/*
WORKDIR /thirdparty
RUN sed -Ei 's/# deb-src /deb-src /' /etc/apt/sources.list && \
    apt-get update && \
    apt-get source ${DEPENDENCIES} && \
    rm -rf /var/lib/apt/lists/*
# setup Python
ENV PYTHON python3.6
RUN apt-get update && \
    apt-get install -y --no-install-recommends python3-pip python3-dev lib${PYTHON}=3.6.9-1~18.04 && \
    rm -rf /var/lib/apt/lists/*
ARG package_url=ARG package_url=http://registrationcenter-download.intel.com/akdlm/irc_nas/16612/l_openvino_toolkit_p_2020.2.120.tgz
ARG TEMP_DIR=/tmp/openvino_installer
WORKDIR ${TEMP_DIR}
ADD ${package_url} ${TEMP_DIR}
# install product by installation script
ENV INTEL_OPENVINO_DIR /opt/intel/openvino
RUN tar -xzf ${TEMP_DIR}/*.tgz --strip 1
RUN sed -i 's/decline/accept/g' silent.cfg && \
    ${TEMP_DIR}/install.sh -s silent.cfg && \
    ${INTEL_OPENVINO_DIR}/install_dependencies/install_openvino_dependencies.sh
WORKDIR /tmp
RUN rm -rf ${TEMP_DIR}
# installing dependencies for package
WORKDIR /tmp
RUN ${PYTHON} -m pip install --no-cache-dir setuptools && \
    find "${INTEL_OPENVINO_DIR}/" -type f -name "*requirements*.*" -path "*/${PYTHON}/*" -exec ${PYTHON} -m pip install --no-cache-dir -r "{}" \; && \
    find "${INTEL_OPENVINO_DIR}/" -type f -name "*requirements*.*" -not -path "*/post_training_optimization_toolkit/*" -not -name "*windows.txt"  -not -name "*ubuntu16.txt" -not -path "*/python3*/*" -not -path "*/python2*/*" -exec ${PYTHON} -m pip install --no-cache-dir -r "{}" \;
WORKDIR ${INTEL_OPENVINO_DIR}/deployment_tools/open_model_zoo/tools/accuracy_checker
RUN source ${INTEL_OPENVINO_DIR}/bin/setupvars.sh && \
    ${PYTHON} -m pip install --no-cache-dir -r ${INTEL_OPENVINO_DIR}/deployment_tools/open_model_zoo/tools/accuracy_checker/requirements.in && \
    ${PYTHON} ${INTEL_OPENVINO_DIR}/deployment_tools/open_model_zoo/tools/accuracy_checker/setup.py install
WORKDIR ${INTEL_OPENVINO_DIR}/deployment_tools/tools/post_training_optimization_toolkit
RUN if [ -f requirements.txt ]; then \
        ${PYTHON} -m pip install --no-cache-dir -r ${INTEL_OPENVINO_DIR}/deployment_tools/tools/post_training_optimization_toolkit/requirements.txt && \
        ${PYTHON} ${INTEL_OPENVINO_DIR}/deployment_tools/tools/post_training_optimization_toolkit/setup.py install; \
    fi;
# Post-installation cleanup and setting up OpenVINO environment variables
RUN if [ -f "${INTEL_OPENVINO_DIR}"/bin/setupvars.sh ]; then \
        printf "\nsource \${INTEL_OPENVINO_DIR}/bin/setupvars.sh\n" >> /home/openvino/.bashrc; \
        printf "\nsource \${INTEL_OPENVINO_DIR}/bin/setupvars.sh\n" >> /root/.bashrc; \
    fi;
RUN find "${INTEL_OPENVINO_DIR}/" -name "*.*sh" -type f -exec dos2unix {} \;
USER openvino
WORKDIR ${INTEL_OPENVINO_DIR}
CMD ["/bin/bash"]

But if I try to launch python program with this line:

from openvino.inference_engine import IECore

It writes ModuleNotFoundError, No module named 'openvino'. I tried to source file setupvars.sh with these commands, but it doesn't help.

RUN /bin/bash -c "source /opt/intel/openvino/bin/setupvars.sh"
RUN source /opt/intel/openvino/bin/setupvars.sh

What should I do to use openvino python apps from docker?


Solution

  • If you are building the Docker image, and trying to run the OpenVINO Python apps outside the docker image it won't work. You can create the Docker image and run Docker image interactively to execute the Python apps within the image. Refer to https://docs.docker.com/engine/reference/run/ for more information on docker run.

    Couple of issues noticed in your Dockerfile when used in my environment. After the changes and steps below, you should be able to import openvino module and run a Python application:

    In Dockerfile line #34:

    // Before:
    apt-get install -y --no-install-recommends python3-pip python3-dev lib${PYTHON}=3.6.9-1~18.04 && \
    // After:
    apt-get install -y --no-install-recommends python3-pip python3-dev lib${PYTHON} && \
    


    In Dockerfile line #36:

    // Before:    
    ARG package_url=ARG package_url=http://registrationcenter-download.intel.com/akdlm/irc_nas/16612/l_openvino_toolkit_p_2020.2.120.tgz
    // After:   
    ARG package_url=http://registrationcenter-download.intel.com/akdlm/irc_nas/16612/l_openvino_toolkit_p_2020.2.120.tgz
    


    After the changes above, run docker build . -t <image-name> (i.e. docker build . -t openvino-ubuntu) to build Docker image. If successful you would see Successfully built bf2280a70ffd Successfully tagged openvino-<image-name>:latest.

    Then run image interactively with docker run -it <image_name> (i.e. docker run -it openvino-ubuntu). You would see something similar to:

    [setupvars.sh] OpenVINO environment initialized
    openvino@ce618ea2bc47:/opt/intel/openvino_2020.2.120$
    


    To verify Python is able to import IECore from openvino module, test with Python interpreter:

    openvino@ce618ea2bc47:/opt/intel/openvino_2020.2.120$ python3
    Python 3.6.9 (default, Apr 18 2020, 01:56:04) 
    [GCC 8.4.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from openvino.inference_engine import IECore
    >>>    
    


    To run OpenVINO Python app, test one of the sample apps in /opt/intel/openvino/deployment_tools/inference_engine/samples/python, for example object_detection_sample_ssd.py:

    openvino@ce618ea2bc47:/opt/intel/openvino_2020.2.120$ python3 /opt/intel/openvino/deployment_tools/inference_engine/samples/python/object_detection_sample_ssd/object_detection_sample_ssd.py
    
    usage: object_detection_sample_ssd.py [-h] -m MODEL -i INPUT [INPUT ...]
                                      [-l CPU_EXTENSION] [-d DEVICE]
                                      [--labels LABELS] [-nt NUMBER_TOP]
    object_detection_sample_ssd.py: error: the following arguments are required: -m/--model, -i/--input