Part 1 (Virtual Environment)

This section of the tutorial will walk you through creating the necessary virtual environment for you to build a Pytorch stage that does basic image detection using resnet50.

It’s a good idea to complete the standard introductory tutorial before moving on to this tutorial.

There are a few assumptions:

  • Ark is installed in ${APP_ROOT}/ark
  • You have successfully built Ark (and all required dependencies are installed)

Creating the Environment

First, let’s make a tutorial directory to do our work in.

cd ${APP_ROOT}/ark
mkdir -p tutorial

Add this to the top-level ${APP_ROOT}/CMakeLists.txt file:

add_subdirectory(tutorial)

Next, let’s build out the CMakeLists.txt file:

add_python_venv(
    tutorial_venv
    PACKAGES
    torch torchvision opencv-python
    ARK_LIBRARIES
    "${ARK_SOURCE_ROOT_DIR}/ark/python/pyserialize"
    "${ARK_SOURCE_ROOT_DIR}/ark/python/pypipeline"
    RBUFS
    ark::python_control_messages
    ark::image_messages)

There’s a few things going on here. First, we’ll create a virtualenv known as tutorial_venv. This will be placed in your build/ark_python_venvs/tutorial_venv directory.

It will install the torch, torchvision, and opencv-python modules via pip into the venv. It will then copy the pyserialize and pypipeline Ark python libraries into that venv, and finally, generate rbuf parsers for the control messages and image message targets.

Next, in Step 2, we’ll work on initializing Pytorch itself.