Skip to content

Latest commit

 

History

History
146 lines (101 loc) · 8.62 KB

OV_docker_VScode.md

File metadata and controls

146 lines (101 loc) · 8.62 KB

Using OpenVINO Docker containers via VS Code

Introduction

The purpose of this tutorial is to examine Intel® Distribution of OpenVINO™ toolkit development containers.

This tutorial provides step-by-step instructions to demonstrate how to set up an OpenVINO™ custom development container under Visual Studio Code* to use it as your full-time development environment.

Prerequisites

This tutorial requires the following:

Overview

Intel® Distribution of OpenVINO™ toolkit is produced from different open source and closed source repositories and components. As well OpenVINO has a couple of dependencies which need to be present on your computer. Additionally, to install some of them, you need to have root/admin rights. This might not be desirable. Using Docker and Visual Studio Code integration represents a much cleaner way of development.

We prepared Dockerfiles for custom development of OpenVINO™ from source based on Ubuntu 18 and Ubuntu 20. They include the following components:

You can customize Cmake* build parameters for OpenVINO itself and OpenCV as well. Then you can integrate that image into VS Code and use all opportunities of the visual code editor and Debug mode for regular development.

Docker and VS Code integration

Build OpenVINO custom development Docker

The first step, we need to build a OpenVINO™ Docker image, by default it uses Debug mode and master branch for all repositories. Go to the Docker CI repository local copy and run docker build from docker_ci/dockerfiles/<os>/build_custom folder:

docker build -t openvino-master .

The second step, we need to run it for future usage:

docker run -it --rm --name openvino openvino-master

By default, the container runs under root user.

  • -it option needs to run container in an interactive mode
  • --rm option needs to remove container after execution
  • --name option sets name for container to simplify access to it

Now, we can attach to the container from VS Code.

Integrate VS Code and OpenVINO container

Fire up VS Code:

code .

Note: You can use a container on a remote host as well. At first you need connect to the remote host and then execute connection to the container. See explicit instructions on VS Code site.

To attach to a Docker container, either select Remote-Containers: Attach to Running Container... from the Command Palette (F1) or use the Remote Explorer in the Activity Bar and from the Containers view, select the Attach to Container inline action on the container you want to connect to.

Then, you can open OpenVINO build and repositories in VS Code editor:

  • Open Explorer -> Open Folder -> /opt/intel/openvino
  • Open Explorer -> Open Folder -> /opt/intel/repo

You can find OpenVINO samples in /opt/intel/openvino/deployment_tools/inference_engine/samples folder, lets try to debug some of them.

Debug C++ sample

Prerequisites: Install Microsoft C/C++ Extension to VS Code

To build the C++ sample applications for Linux, go to the /opt/intel/openvino/inference_engine/samples/cpp directory, respectively, and run the build_samples.sh script. By default, it builds C++ samples in Release mode.

Lets build samples in Debug mode. We need to update build_samples.sh script and change Release to Debug on #60 line "cmake -DCMAKE_BUILD_TYPE=Debug "$SAMPLES_PATH"" and run the script.

Then, you can see built samples in /root/inference_engine_cpp_samples_build/intel64/Debug/ folder.

Select the Run icon in the Activity Bar on the side of VS Code to bring up the Run view. You can also use the keyboard shortcut Ctrl+Shift+D. If running and debugging is not yet configured (no launch.json has been created), VS Code shows the Run start view. Click on "create a launch.json file" link and select an option "C/C++ (gdb) Launch". Please update launch.json with the following settings:

        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "/root/inference_engine_cpp_samples_build/intel64/Debug/hello_query_device",
            "args": [],
            "stopAtEntry": false,
            "cwd": "/root/inference_engine_cpp_samples_build/intel64/Debug/",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ]
        }

After that you can access to the launch.json file via default command palette flow: View -> Command Palette... (F1) -> Open launch.json.

Now, you can set a Breakpoint on any place of samples/cpp/hello_query_device/main.cpp sample and run Debug (F5).

Debug Python sample

Prerequisites: Install Python extention to VS Code

Lets try Hello Query Device Python* Sample which queries Inference Engine devices and prints their metrics and default configuration values. You need to setup Python interpreter in VS Code: View -> Command Palette... (F1) -> Python: Select Interpreter to run Python sample.

Then you need to Add Configuration for the Python sample. Select the Run icon in the Activity Bar on the side of VS Code to bring up the Run view. You can also use the keyboard shortcut Ctrl+Shift+D. If running and debugging is not yet configured (no launch.json has been created), VS Code shows the Run start view. Click on "create a launch.json file" link and select an option "Python: Current file". You will see Debug Configuration with the following settings:

        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "integratedTerminal"
        }

After that you can access to the launch.json file via default command palette flow: View -> Command Palette... (F1) -> Open launch.json.

Now, you can set a Breakpoint on any place of samples/python/hello_query_device/hello_query_device.py sample and run Debug (F5).

Summary

In this article, we briefly introduced the debugging process using OpenVINO custom development container and VS Code editor. Of course, there is much more to try. We hope that this article has motivated you to try it yourself and maybe continue to explore all the possibilities of OpenVINO Docker images.

References