2021년 2월 12일 금요일

Jetpack 4.5 - Install the latest version of OpenPose on Jetson Nano

 OpenPose(https://github.com/CMU-Perceptual-Computing-Lab/openpose) is one of the most popular pose estimation framework. 




There was no problem in installing OpenPose up to the Jetpack 4.4DP version, but when OpenPose was installed in the JetPack 4.4 Production Release, an error occurred. The cause of this problem occurred when some of the CUDA functions used in Caffe were missing. This is explained in detail in Jetson Xavier NX-Human Pose estimation using OpenPose.

However, OpenPose version 1.7.0 released on November 17th, 2020 seems to have solved this problem. If you look at the OpenPose installation documentation, you will find the following contents.

OpenPose uses a custom fork of Caffe (rather than the official Caffe master). Our custom fork is only updated if it works on our machines, but we try to keep it updated with the latest Caffe version. This version works on a newly formatted machine (Ubuntu 16.04 LTS) and in all our machines (CUDA 8 and 10 tested). The default GPU version is the master branch, which it is also compatible with CUDA 10 without changes (official Caffe version might require some changes for it). We also use the OpenCL and CPU tags if their CMake flags are selected. We only modified some Caffe compilation flags and minor details.

Alternatively, you can use your own Caffe distribution on Ubuntu/Mac by 1) disabling BUILD_CAFFE, 2) setting Caffe_INCLUDE_DIRS to {CAFFE_PATH}/include/caffe, and 3) setting Caffe_LIBS to {CAFFE_PATH}/build/lib/libcaffe.so, as shown in the image below. Note that cuDNN-compatible Caffe version is required in order to get the maximum possible accuracy in OpenPose.


I will install the latest version of OpenPose once again in JetPack 4.5 of the newly installed Jetson Nano.


Prerequisites

For reference, I installed OpenPose while upgrading to OpenCV 4.5. But I think it will be fine with OpenCV 4.1.1 provided by JetPack 4.5.


cmake version check

    To build Openpose on the Jetson Nano, you should have cmake version 3.12.2 or higher. First check the cmake version.

    cmake --version
    


    If your Jetson Nano's cmake version is lower than 3.12.2, remove the old cmake and rebuild from source codes. Check the latest version at https://github.com/Kitware/CMake/releases . At this time(2021.02.9), Ver 3.19.4 is the latest cmake version.  I used the --qt-gui option in bootstrap to build cmake-gui together.

    apt-get update
    apt-get install -y libssl-dev libcurl4-openssl-dev qt5-default
    apt-get install -y build-essential libboost-all-dev libboost-dev libhdf5-dev libatlas-base-dev
    apt-get install -y python3-dev python3-pip
    apt-get remove -y cmake
    cd /usr/local/src
    wget https://github.com/Kitware/CMake/releases/download/v3.19.4/cmake-3.19.4.tar.gz
    tar -xvzf cmake-3.19.4.tar.gz
    cd cmake-3.19.4
    ./bootstrap --qt-gui
    make -j4
    make install


    Then you must restart your ssh session. The cmake and cmake-gui are created in the /cmake-3.19.4/bin directory. If the version of cmake or cmake-gui has not been updated in a new ssh or local terminal after make install, copy the cmake and cmake-gui files from the above directory to the /usr/bin directory.


    Install OpenPose for JetPack 4.5


    Install Protocol Buffer

    First, install Google's protocol buffer. 

    apt-get install -y libprotobuf-dev protobuf-compiler libgflags-dev libgoogle-glog-dev
    <Protocol Buffer installation>

    Install OpenPose 1.7.0

    As of now, the latest version of OpenPose is 1.7.0, released on November 17th, 2020. 
    Download the source code. 

    root@spypiggy-nano:/#cd /usr/local/src
    root@spypiggy-nano:/usr/local/src#wget https://github.com/CMU-Perceptual-Computing-Lab/openpose/archive/v1.7.0.tar.gz
    root@spypiggy-nano:/usr/local/src#tar -xvzf v1.7.0.tar.gz
    root@spypiggy-nano:/usr/local/src#cd openpose-1.7.0/
    root@spypiggy-nano:/usr/local/src/openpose-1.7.0#cd 3rdparty
    
    root@spypiggy-nano:/usr/local/src/openpose-1.7.0/3rdparty#git clone https://github.com/CMU-Perceptual-Computing-Lab/caffe.git
    root@spypiggy-nano:/usr/local/src/openpose-1.7.0/3rdparty#git clone https://github.com/pybind/pybind11.git


    <Download Openpose source code>

    step1. Enable BUILD_PYTHON OPTION 

    The following is the procedure to create a Makefile using cmake. This time, I will use cmake-gui. You can also use cmake in the shell. Run cmake-gui and specify the source code directory and build directory as below. Be sure to check the BUILD_PYTHON option.


    step2. Disable USE_CUDNN option


    <cmake-gui build option>


    The use of CUDNN must be excluded in the option. If you build OpenPose 1.7.0 from JetPack 4.5 and you use this option, the build is fine, but phenomena such as system down or segmentation fault(core dump) may occur when running. 
    I do not yet know the exact cause of this phenomenon. For now, this option is excluded to prevent severe errors at runtime.

    step3. Generate Makefile 

    After checking the options, click the Configure button again. Maybe the red area will turn white. Perhaps this step will be time consuming. And finally, click Generate button to generate Makefile.



    Now, a build directory contains files necessary for build including Makefile.
    When the Makefile is properly created, run make command.

    root@spypiggy-nano:/usr/local/src/openpose-1.7.0/build# make -j4
    
    root@spypiggy-nano:/usr/local/src/openpose-1.7.0/build# make install
    root@spypiggy-nano:/usr/local/src/openpose-1.7.0/build# cd python
    root@spypiggy-nano:/usr/local/src/openpose-1.7.0/build/python# make -j4


    Python import Problem 

    Before you run python samples, first check the openpose python file. Yes it's under the "openpose installation directory/build/python/openpose".

    It's time to copy our OpenPose python modules to python3.6 path directory(/usr/lib/python3.6/dist-packages). Then you can import openpose without path problem.

    cp -r /usr/local/src/openpose-1.7.0/build/python/openpose/ /usr/lib/python3.6/dist-packages


    Let's test your openpose python library.

    root@spypiggy-nano:/usr/local/src/openpose-1.7.0/build/python/openpose# python3
    Python 3.6.9 (default, Oct  8 2020, 12:12:24)
    [GCC 8.4.0] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import openpose
    >>>
    

    Yes, I finally installed the OpenPose 1.7.0 version successfully.


    Run a sample program 

    Let's run a sample program to test whether the OpenPose is properly installed.

    root@spypiggy-nano:/usr/local/src/openpose-1.7.0# ./build/examples/openpose/openpose.bin --video ./examples/media/video.avi  --net_resolution "256x128"
    Starting OpenPose demo...
    Configuring OpenPose...
    Starting thread(s)...
    Auto-detecting all available GPUs... Detected 1 GPU(s), using 1 of them starting at GPU 0.
    

    If you see this output, it's a successfull installation.


    You have now confirmed that OpenPose is working properly on Jetson Nano.

    Be Careful : The Jetson Nano has 4GB of memory. 4GB of memory is not enough to run OpenPose. In the example above, I used the --net_resolution "256x128" option. The reason for using this option is related to memory usage. As the resolution of this option value increases, the processing speed decreases and the memory usage increases. If the resolution is increased above a certain level, the process is forcibly terminated due to insufficient memory. 

    If you don't use the --net_resolution option, OpenPose will find and use the optimal value. For a 16:9 ratio image, the default value of "656x368" is used. This value must be a multiple of 16.

    root@spypiggy-nano:/usr/local/src/openpose-1.7.0# ./build/examples/openpose/openpose.bin --video ./examples/media/video.avi
    Starting OpenPose demo...
    Configuring OpenPose...
    Starting thread(s)...
    Auto-detecting all available GPUs... Detected 1 GPU(s), using 1 of them starting at GPU 0.
    Killed

    <openpose process is killed due to insufficient memory>

    JetPack's Ubuntu desktop takes up a lot of memory. Therefore, if you replace the desktop GUI with a lightweight LXDE, you can get an additional 500MB to 1GB of memory. How to acquire additional memory using LXDE is described below:


    Wrapping up 

    Refer to the articles below for how to use OpenPose in the Jetson Nano, Xavier NX, and TX2 series.


    If you want to install OpenPose 1.7.0 on the Xavier NX, refer to this article:


    In the next article, I'll cover how to use Python with OpenPose 1.7.0.


    댓글 2개:

    1. When I try to run the example I got
      Error:
      Unity plugin only available on Windows.

      Coming from:
      -/usr/local/src/openpose-1.7.0/src/openpose/utilities/errorAndlog.cpp:DebugInUnity():47

      any idea how to solve it?

      답글삭제
      답글
      1. As you can see from the error message, it seems that unity plugin is only available on Windows 7, 8, 10.
        Pls refer the document at https://github.com/CMU-Perceptual-Computing-Lab/openpose_unity_plugin/blob/master/doc/installation.md .

        삭제