1

我正在尝试构建一个包装在为 Openvino 模型提供服务的 docker 映像中的 API。如何从 Dockerfile 本身运行“setupvars.sh”,以便我的应用程序可以访问它?

我尝试使用 RUN 运行脚本。例如: RUN /bin/bash setupvars.sh 或 RUN ./setupvars.sh 。但是,它们都不起作用,我得到 ModelNotFoundError: no module named openvino

RUN $INSTALL_DIR/install_dependencies/install_openvino_dependencies.sh
RUN cd /opt/intel/openvino/deployment_tools/model_optimizer/install_prerequisites && sudo ./install_prerequisites_tf.sh
COPY . /app
WORKDIR /app
RUN apt autoremove -y && \
    rm -rf /openvino /var/lib/apt/lists/*
RUN /bin/bash -c "source $INSTALL_DIR/bin/setupvars.sh"
RUN echo "source $INSTALL_DIR/bin/setupvars.sh" >> /root/.bashrc
CMD ["/bin/bash"]
RUN python3 -m pip install opencv-python
RUN python3 test.py

我希望我的 gunicorn 应用程序可以访问 OpenVino,该应用程序将在 docker 映像中为模型提供服务

4

3 回答 3

0

下一个命令对我有用。

ARG OPENVINO_DIR=/opt/intel/computer_vision_sdk


# Unzip the OpenVINO installer
RUN cd ${APP_DIR} && tar -xvzf l_openvino_toolkit*

# installing OpenVINO dependencies
RUN cd ${APP_DIR}/l_openvino_toolkit* && \
    ./install_cv_sdk_dependencies.sh

# installing OpenVINO itself
RUN cd ${APP_DIR}/l_openvino_toolkit* && \
    sed -i 's/decline/accept/g' silent.cfg && \
    ./install.sh --silent silent.cfg

# Setup the OpenVINO environment
RUN /bin/bash -c "source ${OPENVINO_DIR}/bin/setupvars.sh"
于 2019-06-06T20:13:10.667 回答
0

前面两个回答中提到,setupvars.sh脚本设置了OpenVINO需要的环境变量。

但是,您可以将变量添加到 Dockerfile 中,而不是每次都运行它。在编写 Dockerfile 时运行:

CMD /bin/bash -c "source /opt/intel/openvino/bin/setupvars.sh && printenv"

这将为您提供环境变量设置的值。您可能还想在printenv不设置 OpenVINO 变量的情况下运行:

CMD /bin/bash printenv

比较这两个输出可以让您准确地确定setupvars.sh脚本的设置。

ENV一旦知道脚本设置的值,就可以使用指令将它们设置为 Dockerfile 的一部分。我不会复制它,因为它可能特定于您的设置,但就我而言,这最终看起来像:

ENV PATH=/opt/intel/openvino/deployment_tools/model_optimizer:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
ENV LD_LIBRARY_PATH=/opt/intel/openvino/opencv/lib:/opt/intel/openvino/deployment_tools/ngraph/lib:/opt/intel/openvino/deployment_tools/inference_engine/external/tbb/lib::/opt/intel/openvino/deployment_tools/inference_engine/external/hddl/lib:/opt/intel/openvino/deployment_tools/inference_engine/external/omp/lib:/opt/intel/openvino/deployment_tools/inference_engine/external/gna/lib:/opt/intel/openvino/deployment_tools/inference_engine/external/mkltiny_lnx/lib:/opt/intel/openvino/deployment_tools/inference_engine/lib/intel64
ENV INTEL_CVSDK_DIR=/opt/intel/openvino
ENV OpenCV_DIR=/opt/intel/openvino/opencv/cmake
ENV TBB_DIR=/opt/intel/openvino/deployment_tools/inference_engine/external/tbb/cmake
# The next one will be whatever your working directory is
ENV PWD=/workspace
ENV InferenceEngine_DIR=/opt/intel/openvino/deployment_tools/inference_engine/share
ENV ngraph_DIR=/opt/intel/openvino/deployment_tools/ngraph/cmake
ENV SHLVL=1
ENV PYTHONPATH=/opt/intel/openvino/python/python3.6:/opt/intel/openvino/python/python3:/opt/intel/openvino/deployment_tools/tools/post_training_optimization_toolkit:/opt/intel/openvino/deployment_tools/open_model_zoo/tools/accuracy_checker:/opt/intel/openvino/deployment_tools/model_optimizer
ENV HDDL_INSTALL_DIR=/opt/intel/openvino/deployment_tools/inference_engine/external/hddl
ENV _=/usr/bin/printenv
于 2021-06-30T09:04:08.313 回答
0

每次启动容器时都需要重新运行它,因为这些变量仅适用于会话。

选项 1:运行您的应用程序,如下所示:

CMD /bin/bash -c "source /opt/intel/openvino/bin/setupvars.sh && python test.py"

选项 2(未测试):将 source 命令添加到您的 .bashrc 中,以便每次启动时都会运行它

# Assuming running as root
RUN echo "/bin/bash -c 'source /opt/intel/openvino/bin/setupvars.sh'" >> ~root/.bashrc
CMD python test.py

对于 Dockerfile 的其余部分,这里有一个指南(也未经测试,并且不包括上述内容): https ://docs.openvinotoolkit.org/latest/_docs_install_guides_installing_openvino_docker_linux.html

于 2020-04-26T16:14:30.583 回答