Running PyOpenPose on Google Colab

2.6k views Asked by At

I'm trying to run PyOpenPose on Google Colab.

It requires CUDA, this is how I did it.

!wget https://developer.nvidia.com/compute/cuda/10.0/Prod/local_installers/cuda-repo-ubuntu1804-10-0-local-10.0.130-410.48_1.0-1_amd64 -O cuda-repo-ubuntu1804-10-0-local-10.0.130-410.48_1.0-1_amd64.deb
!dpkg -i cuda-repo-ubuntu1804-10-0-local-10.0.130-410.48_1.0-1_amd64.deb
!apt-key add /var/cuda-repo-10-0-local/7fa2af80.pub
!apt-get update
!apt-get install cuda

It required OpenCV3, which I simply installed using -

!apt-get -qq install -y libsm6 libxext6 && pip install -q -U opencv-python

To solve a bunch of errors, I installed several other packages-

!apt-get install build-essential checkinstall pkg-config yasm
!apt-get install gfortran
!apt-get install libjpeg8-dev libjasper-dev libpng12-dev
!apt-get install libtiff5-dev
!apt-get install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev
!apt-get install libxine2-dev libv4l-dev
!apt-get install libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev
!apt-get install qt5-default libgtk2.0-dev libtbb-dev
!apt-get install libatlas-base-dev
!apt-get install libfaac-dev libmp3lame-dev libtheora-dev
!apt-get install libvorbis-dev libxvidcore-dev
!apt-get install libopencore-amrnb-dev libopencore-amrwb-dev
!apt-get install x264 v4l-utils
!apt-get install libgoogle-glog-dev
!apt-get install libopencv-dev

Then I installed CuDNN like this -

!wget "http://developer.download.nvidia.com/compute/redist/cudnn/v5.1/cudnn-8.0-linux-x64-v5.1.tgz"
!tar -xvzf cudnn-8.0-linux-x64-v5.1.tgz
!cp cuda/include/cudnn.h /usr/local/cuda/include
!cp cuda/lib64/libcudnn* /usr/local/cuda/lib64
!chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn*
!dpkg -i libcudnn7_7.3.0.29-1+cuda10.0_amd64.deb
!apt-get install -f

Then I cloned OpenPose as recommended. Changed to the dir. Set os.environ['OPENPOSE_ROOT'] = os.getcwd() Made a build directory. Installed cmake. Then tried to build it which worked.

!mkdir build
os.chdir("build")
!apt update
!apt install -y cmake
!cmake ..

Moving on, I went ahead and made a build directory in PyOpenPose. Tried running it and it said it needed Boost libraries. I installed it using these commands -

!apt-get install libboost-all-dev

I can see the boost libraries present in usr/lib/x86_64-linux-gnu (set to os.environ['BOOST_LIBRARYDIR'])

While boost sits in /usr/include/boost (set to os.environ['BOOST_ROOT'])

After all this effort, I'm stuck with this error on using !cmake .. from the build directory :

cmake: /usr/local/lib/libcurl.so.4: no version information available 
(required by cmake)
Install prefix is set to: /usr/local
Generating with build type: Release
-- Could NOT find Doxygen (missing: DOXYGEN_EXECUTABLE) 
-- Boost version: 1.65.1
CMake Warning at /usr/share/cmake-3.10/Modules/FindBoost.cmake:1626     (message):
  No header defined for python2; skipping header check
Call Stack (most recent call first):
  CMakeLists.txt:61 (find_package)

CMake Error at /usr/share/cmake-3.10/Modules/FindBoost.cmake:1947 (message):
  Unable to find the requested Boost libraries.

  Boost version: 1.65.1

  Boost include path: /usr/include

  Could not find the following Boost libraries:

      boost_python2

  Some (but not all) of the required Boost libraries were found.  You may
  need to install these additional Boost libraries.  Alternatively, set
  BOOST_LIBRARYDIR to the directory containing Boost libraries or     BOOST_ROOT
  to the location of Boost.
Call Stack (most recent call first):
  CMakeLists.txt:61 (find_package)


-- The following REQUIRED packages have been found:
 * Threads
 * CUDA
 * OpenCV (required version >= 3)
 * PythonLibs (required version == 2.7)

-- The following OPTIONAL packages have not been found:
 * Doxygen

-- The following REQUIRED packages have not been found:
 * Boost

-- Configuring incomplete, errors occurred!
See also "/content/PyOpenPose/build/CMakeFiles/CMakeOutput.log".
See also "/content/PyOpenPose/build/CMakeFiles/CMakeError.log".

My Runtime is Python3 with GPU. How can I fix this, and is everything else okay so far?

UPDATE 1: !cmake -D WITH_PYTHON3=True .. Fixed that. Now stuck at detecting PythonLibs.

ERROR:

CMake Error at /usr/share/cmake-    3.10/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
  Could NOT find PythonLibs: Found unsuitable version "2.7.15rc1", but
  required is exact version "3" (found
  /usr/lib/x86_64-linux-gnu/libpython2.7.so)
Call Stack (most recent call first):
  /usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:376     (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake-3.10/Modules/FindPythonLibs.cmake:262     (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  CMakeLists.txt:72 (find_package)
1

There are 1 answers

1
Sam On

here is how I managed to make Openpose work in my googlecolab:

Just enter the following in one googlecolab cell and run it.

import os
from os.path import exists, join, basename, splitext

git_repo_url = 'https://github.com/CMU-Perceptual-Computing-Lab/openpose.git'
project_name = splitext(basename(git_repo_url))[0]
if not exists(project_name):
  # see: https://github.com/CMU-Perceptual-Computing-Lab/openpose/issues/949
  # install new CMake becaue of CUDA10
  !wget -q https://cmake.org/files/v3.13/cmake-3.13.0-Linux-x86_64.tar.gz
  !tar xfz cmake-3.13.0-Linux-x86_64.tar.gz --strip-components=1 -C /usr/local
  # clone openpose
  !git clone -q --depth 1 $git_repo_url
  !sed -i 's/execute_process(COMMAND git checkout master WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}\/3rdparty\/caffe)/execute_process(COMMAND git checkout f019d0dfe86f49d1140961f8c7dec22130c83154 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}\/3rdparty\/caffe)/g' openpose/CMakeLists.txt
  # install system dependencies
  !apt-get -qq install -y libatlas-base-dev libprotobuf-dev libleveldb-dev libsnappy-dev libhdf5-serial-dev protobuf-compiler libgflags-dev libgoogle-glog-dev liblmdb-dev opencl-headers ocl-icd-opencl-dev libviennacl-dev
  # install python dependencies
  !pip install -q youtube-dl
  # build openpose
  !cd openpose && rm -rf build || true && mkdir build && cd build && cmake .. && make -j`nproc`
  
from IPython.display import YouTubeVideo