Tf-pose-estimation: Not able to run pose estimation on ROS

Created on 25 May 2020  路  1Comment  路  Source: ildoonet/tf-pose-estimation

Hello! I was trying to execute tfpose_ros in Ubuntu 18.04 LTS, Python 3.6 and ROS Melodic. I have few issues with it:

  1. I tried to build the code using catkin_make. This happened successfully but when I tried to execute it, I got an error saying

ImportError: dynamic module does not define module export function (PyInit_cv_bridge_boost)

From what I read on the internet, it is because 'PyInit_cv_bridge_boost' which is present in ROS library will not run on Python 3.

To fix it, I created a new catkin workspace by following these steps:

```{r, attr.output='style="max-height: 100px;"'}

python-catkin-tools is needed for catkin tool

python3-dev and python3-catkin-pkg-modules is needed to build cv_bridge

python3-numpy and python3-yaml is cv_bridge dependencies

ros-kinetic-cv-bridge is needed to install a lot of cv_bridge deps. Probaply you already have it installed.

sudo apt-get install python-catkin-tools python3-dev python3-catkin-pkg-modules python3-numpy python3-yaml ros-kinetic-cv-bridge

Create catkin workspace

mkdir catkin_workspace
cd catkin_workspace
catkin init

Instruct catkin to set cmake variables

catkin config -DPYTHON_EXECUTABLE=/usr/bin/python3 -DPYTHON_INCLUDE_DIR=/usr/include/python3.5m -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.5m.so

Instruct catkin to install built packages into install place. It is $CATKIN_WORKSPACE/install folder

catkin config --install

Clone cv_bridge src

git clone https://github.com/ros-perception/vision_opencv.git src/vision_opencv

Find version of cv_bridge in your repository

apt-cache show ros-kinetic-cv-bridge | grep Version
Version: 1.12.8-0xenial-20180416-143935-0800

Checkout right version in git repo. In our case it is 1.12.8

cd src/vision_opencv/
git checkout 1.12.8
cd ../../

Build

catkin build cv_bridge

Extend environment with new package

source install/setup.bash --extend

Even though this helped me fix the 'PyInit_cv_bridge_boost' error, I got few more errors. The first one was 'Package name and basename mismatch' error. I fixed it by following #547 . This gave me another error

```{r, attr.output='style="max-height: 100px;"'}
Errors     << tfpose_ros:install /home/linuxuser/catkin_workspace/logs/tfpose_ros/build.install.000.log                                              
--2020-05-26 02:02:33--  http://download686.mediafire.com/x4qhgkd2kcug/qlzzr20mpocnpa3/graph_opt.pb
Resolving download686.mediafire.com (download686.mediafire.com)... 205.196.120.134
Connecting to download686.mediafire.com (download686.mediafire.com)|205.196.120.134|:80... connected.
HTTP request sent, awaiting response... 416 Range Not Satisfiable

    The file is already fully retrieved; nothing to do.

file pafprocess.py (for module pafprocess) not found
error: package directory 'tf_pose_data' does not exist
CMake Error at catkin_generated/safe_execute_install.cmake:4 (message):

  execute_process(/home/linuxuser/catkin_workspace/build/tfpose_ros/catkin_generated/python_distutils_install.sh)
  returned error code
Call Stack (most recent call first):
  cmake_install.cmake:132 (include)


make: *** [install] Error 1
cd /home/linuxuser/catkin_workspace/build/tfpose_ros; catkin build --get-env tfpose_ros | catkin env -si  /usr/bin/make install; cd -

Does anyone know how to fix it? Is this the right way to execute tfpose_ros?

Most helpful comment

I was finally able to make it work. Here is my configuration:

  • OpenCV 3.4.2 (You must use OpenCV 3 only as this will not work for 4)
  • Tensorflow-GPU 1.14
  • Ubuntu 16.04.6 LTS
  • CUDA 10.0.130 (It might say that the installation failed but it actually works )
  • cuDNN v7.4.2.24
  • NVIDIA 430.64 (Installed it from PPA repository)

I have typed this out for the above configuration. It might or might not work for other combinations of these packages. I would recommend you to try it in a virtual enviroment (preferably conda) because it will help you to roll back in case you make any mistake.

  1. Install pip, git, cython, swig, tk and then all the packages listed in requirements.txt. I would recommend you to use NumPy 1.16.4.
  2. Clone the repository and try to run the program. This is just to make sure that all the requirements have been installed and the program is working correctly.
  3. Now install ROS Kinetic (Refer to the ROS website for detailed tutorial). I'll list all the commands required to run this.
    ```{r, attr.output='style="max-height: 100px;"'}
    sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
    sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
    sudo apt-get update
    sudo apt-get install ros-kinetic-desktop-full
    echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
    source ~/.bashrc
    sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
    sudo apt install python-rosdep
    sudo rosdep init
    rosdep update
4. Now create a new directory in home and configure it for ROS
```{r, attr.output='style="max-height: 100px;"'}
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/
catkin_make
echo "source devel/setup.bash" >> ~/.bashrc
source ~/.bashrc

Please use catkin_make and not catkin build

  1. Now you will need to install additional dependencies to make it run
    ```{r, attr.output='style="max-height: 100px;"'}
    sudo apt-get install python-catkin-tools python3-dev python3-catkin-pkg-modules python3-numpy python3-yaml ros-kinetic-cv-bridge
    pip install catkin_pkg
    pip install rospkg
    pip3 install catkin_pkg
    pip3 install empy
    pip install empy
These packages should be more than enough. If the build fails (later on when you build the code) because certain package is missing, then install it.

6. Now run these commands (make sure you are inside the catkin_ws folder)
```{r, attr.output='style="max-height: 100px;"'}
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install ros-kinetic-video-stream-opencv
sudo apt-get install ros-kinetic-image-view
git clone https://github.com/ildoonet/ros-video-recorder.git src/
git clone https://github.com/ildoonet/tf-pose-estimation.git src/
pip install -U setuptools
  1. Now go inside tf-pose-estimation directory and change few things
    a) In package.xml, replace <version>0.1.0</version> with <version>0.1.1</version>
    b) In setup.py, change name='tf-pose' to name='tfpose_ros' and package_dir={'tf_pose_data': 'models'} to package_dir={'tfpose_ros': 'models'}
    c) Don't forget to build the C++ library for post processing

  2. As I mentioned in the issue I raised, there is conflict in python2 and python3 packages. This is how you fix it
    a) Rename cv2.so in /opt/ros/kinetic/lib/python2.7/dist-packages to cv2_renamed.so or anything so that it doesn't get imported. (This is nothing but OpenCV's shared object file for Python 2.7)
    This will make sure that Python3's OpenCV is imported.
    b) Next library is cv_bridge. This is now you fix this
    ```{r, attr.output='style="max-height: 100px;"'}

    Initializing catkin workspace

catkin init

Instruct catkin to set cmake variables

catkin config -DPYTHON_EXECUTABLE=/usr/bin/python3 -DPYTHON_INCLUDE_DIR=/usr/include/python3.5m -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.5m.so
catkin config --install

Clone cv_bridge src

git clone https://github.com/ros-perception/vision_opencv.git src/vision_opencv

Find version of cv_bridge in your repository

apt-cache show ros-kinetic-cv-bridge | grep Version
Version: 1.12.8-0xenial-20180416-143935-0800

Checkout right version in git repo. In my case it was 1.12.8

cd src/vision_opencv/
git checkout 1.12.8
cd ../../

Build

catkin_make cv_bridge

Building all packages

catkin_make

If you encounter this error:
```{r, attr.output='style="max-height: 100px;"'}
CMake Error at /usr/share/cmake-3.5/Modules/FindBoost.cmake:1677 (message):
  Unable to find the requested Boost libraries.

  Boost version: 1.58.0

  Boost include path: /usr/include

  Could not find the following Boost libraries:

          boost_python3

  No Boost libraries were found.  You may need to 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:11 (find_package)

It is because CMake tries to find libboost_python3.so library, but in ubuntu it is libboost_python-py35.so(/usr/lib/x86_64-linux-gnu/libboost_python-py35.so), so you should change line
```{r, attr.output='style="max-height: 100px;"'}
find_package(Boost REQUIRED python3)

```{r, attr.output='style="max-height: 100px;"'}
find_package(Boost REQUIRED python-py35)

in file src/vision_opencv/cv_bridge/CMakeLists.txt and rebuild package (i.e run catkin_make again)

  1. Now change this line in run_video.py:
    ```{r, attr.output='style="max-height: 100px;"'}
    humans = e.inference(image)
```{r, attr.output='style="max-height: 100px;"'}
humans = e.inference(image, resize_to_default=(w > 0 and h > 0), upsample_size=args.resize_out_ratio)
  1. Finally run by typing
    ```{r, attr.output='style="max-height: 100px;"'}
    roslaunch tfpose_ros demo_video.launch
Make sure that this is done in catkin_ws folder(really important!)

You might not be able to see the poses the first time you run it, because it will take some time for the model to load onto the memory. Quit it (Ctrl+C) once the model loads and re-run the program to see the correct output.

I hope this works for you!

P.S In case you make some mistake or you want to re-install ROS, then run these commands to remove ROS packages completely
```{r, attr.output='style="max-height: 100px;"'}
sudo apt-get remove ros-*
sudo apt-get remove ros-melodic-*
sudo apt-get autoremove
sudo rm -rf /etc/ros/
sudo apt update

>All comments

I was finally able to make it work. Here is my configuration:

  • OpenCV 3.4.2 (You must use OpenCV 3 only as this will not work for 4)
  • Tensorflow-GPU 1.14
  • Ubuntu 16.04.6 LTS
  • CUDA 10.0.130 (It might say that the installation failed but it actually works )
  • cuDNN v7.4.2.24
  • NVIDIA 430.64 (Installed it from PPA repository)

I have typed this out for the above configuration. It might or might not work for other combinations of these packages. I would recommend you to try it in a virtual enviroment (preferably conda) because it will help you to roll back in case you make any mistake.

  1. Install pip, git, cython, swig, tk and then all the packages listed in requirements.txt. I would recommend you to use NumPy 1.16.4.
  2. Clone the repository and try to run the program. This is just to make sure that all the requirements have been installed and the program is working correctly.
  3. Now install ROS Kinetic (Refer to the ROS website for detailed tutorial). I'll list all the commands required to run this.
    ```{r, attr.output='style="max-height: 100px;"'}
    sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
    sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
    sudo apt-get update
    sudo apt-get install ros-kinetic-desktop-full
    echo "source /opt/ros/kinetic/setup.bash" >> ~/.bashrc
    source ~/.bashrc
    sudo apt install python-rosdep python-rosinstall python-rosinstall-generator python-wstool build-essential
    sudo apt install python-rosdep
    sudo rosdep init
    rosdep update
4. Now create a new directory in home and configure it for ROS
```{r, attr.output='style="max-height: 100px;"'}
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/
catkin_make
echo "source devel/setup.bash" >> ~/.bashrc
source ~/.bashrc

Please use catkin_make and not catkin build

  1. Now you will need to install additional dependencies to make it run
    ```{r, attr.output='style="max-height: 100px;"'}
    sudo apt-get install python-catkin-tools python3-dev python3-catkin-pkg-modules python3-numpy python3-yaml ros-kinetic-cv-bridge
    pip install catkin_pkg
    pip install rospkg
    pip3 install catkin_pkg
    pip3 install empy
    pip install empy
These packages should be more than enough. If the build fails (later on when you build the code) because certain package is missing, then install it.

6. Now run these commands (make sure you are inside the catkin_ws folder)
```{r, attr.output='style="max-height: 100px;"'}
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install ros-kinetic-video-stream-opencv
sudo apt-get install ros-kinetic-image-view
git clone https://github.com/ildoonet/ros-video-recorder.git src/
git clone https://github.com/ildoonet/tf-pose-estimation.git src/
pip install -U setuptools
  1. Now go inside tf-pose-estimation directory and change few things
    a) In package.xml, replace <version>0.1.0</version> with <version>0.1.1</version>
    b) In setup.py, change name='tf-pose' to name='tfpose_ros' and package_dir={'tf_pose_data': 'models'} to package_dir={'tfpose_ros': 'models'}
    c) Don't forget to build the C++ library for post processing

  2. As I mentioned in the issue I raised, there is conflict in python2 and python3 packages. This is how you fix it
    a) Rename cv2.so in /opt/ros/kinetic/lib/python2.7/dist-packages to cv2_renamed.so or anything so that it doesn't get imported. (This is nothing but OpenCV's shared object file for Python 2.7)
    This will make sure that Python3's OpenCV is imported.
    b) Next library is cv_bridge. This is now you fix this
    ```{r, attr.output='style="max-height: 100px;"'}

    Initializing catkin workspace

catkin init

Instruct catkin to set cmake variables

catkin config -DPYTHON_EXECUTABLE=/usr/bin/python3 -DPYTHON_INCLUDE_DIR=/usr/include/python3.5m -DPYTHON_LIBRARY=/usr/lib/x86_64-linux-gnu/libpython3.5m.so
catkin config --install

Clone cv_bridge src

git clone https://github.com/ros-perception/vision_opencv.git src/vision_opencv

Find version of cv_bridge in your repository

apt-cache show ros-kinetic-cv-bridge | grep Version
Version: 1.12.8-0xenial-20180416-143935-0800

Checkout right version in git repo. In my case it was 1.12.8

cd src/vision_opencv/
git checkout 1.12.8
cd ../../

Build

catkin_make cv_bridge

Building all packages

catkin_make

If you encounter this error:
```{r, attr.output='style="max-height: 100px;"'}
CMake Error at /usr/share/cmake-3.5/Modules/FindBoost.cmake:1677 (message):
  Unable to find the requested Boost libraries.

  Boost version: 1.58.0

  Boost include path: /usr/include

  Could not find the following Boost libraries:

          boost_python3

  No Boost libraries were found.  You may need to 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:11 (find_package)

It is because CMake tries to find libboost_python3.so library, but in ubuntu it is libboost_python-py35.so(/usr/lib/x86_64-linux-gnu/libboost_python-py35.so), so you should change line
```{r, attr.output='style="max-height: 100px;"'}
find_package(Boost REQUIRED python3)

```{r, attr.output='style="max-height: 100px;"'}
find_package(Boost REQUIRED python-py35)

in file src/vision_opencv/cv_bridge/CMakeLists.txt and rebuild package (i.e run catkin_make again)

  1. Now change this line in run_video.py:
    ```{r, attr.output='style="max-height: 100px;"'}
    humans = e.inference(image)
```{r, attr.output='style="max-height: 100px;"'}
humans = e.inference(image, resize_to_default=(w > 0 and h > 0), upsample_size=args.resize_out_ratio)
  1. Finally run by typing
    ```{r, attr.output='style="max-height: 100px;"'}
    roslaunch tfpose_ros demo_video.launch
Make sure that this is done in catkin_ws folder(really important!)

You might not be able to see the poses the first time you run it, because it will take some time for the model to load onto the memory. Quit it (Ctrl+C) once the model loads and re-run the program to see the correct output.

I hope this works for you!

P.S In case you make some mistake or you want to re-install ROS, then run these commands to remove ROS packages completely
```{r, attr.output='style="max-height: 100px;"'}
sudo apt-get remove ros-*
sudo apt-get remove ros-melodic-*
sudo apt-get autoremove
sudo rm -rf /etc/ros/
sudo apt update
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Minotaur-CN picture Minotaur-CN  路  4Comments

juciny picture juciny  路  3Comments

ildoonet picture ildoonet  路  3Comments

siddharthrajpatel picture siddharthrajpatel  路  4Comments

GreatGBL picture GreatGBL  路  4Comments