Daniil-Osokin / lightweight-human-pose-estimation-3d-demo.pytorch

Real-time 3D multi-person pose estimation demo in PyTorch. OpenVINO backend can be used for fast inference on CPU.
Apache License 2.0
656 stars 138 forks source link

#### Cannot load fast pose extraction, switched to legacy slow implementation. #### #37

Closed ccl-private closed 3 years ago

ccl-private commented 3 years ago

how to load fast pose extraction?

Daniil-Osokin commented 3 years ago

Hi! To use fast pose extractor, please follow prerequisites, mainly successfully run setup.py build_ext and add result to PYTHONPATH.

ccl-private commented 3 years ago

thanks~I forget that~

Fan-loewe commented 3 years ago

Hi,

I want to use the fast pose extractor in ROS, I successfully built the setup.py and add the result to PYTHONPATH. when I run sys.path, it is able to show the path '/home/aegis/catkin_ws/src/pose_estimation/src/pose_estimation/pose_extractor/build'

I could "import pose_extractor" successfully, but it fails when "from pose_extractor import extract_poses".

Does that mean C++ library was not imported to python interface?

Thanks!!

Daniil-Osokin commented 3 years ago

Hi, do you have pose_extractor.so inside pose_extractor/build folder? If so, what is the output of (should be something like 00000000000030c0t_ZL13extract_posesP7_objectS0_):

nm pose_extractor/build/pose_extractor.so | grep extract_poses

I have just exported to PYTHONPATH and demo works (got +10 FPS):

~/lightweight-human-pose-estimation-3d-demo.pytorch$ export PYTHONPATH=./pose_extractor/build/:$PYTHONPATH
~/lightweight-human-pose-estimation-3d-demo.pytorch$ python demo.py -m ~/Downloads/human-pose-estimation-3d.pth --video 0
Fan-loewe commented 3 years ago

Hi, yes I have pose_extractor.so inside, the output shows: 00000000000032a8 t _ZL13extract_posesP7objectS0

Originally the demo also works on me. When I apply into ROS, I need to recompile demo.python with catkin make. I think I could not access this build folder in my catkin workspace even if it already in my python environment. What is the mechanism to link the .so file?

Daniil-Osokin commented 3 years ago

It looks like things work in a different way in ROS, you can check this tutorial, it has steps to wrap C++ function under ROS to call in Python. Or may be some other recipes will work (I do not have a ROS to check).

Fan-loewe commented 3 years ago

Hi Daniil, it works now. Thanks!

Daniil-Osokin commented 3 years ago

Great! Can you please tell what was helped or may be attach a diff with changes for the future readers (and me :), it is really interesting how code should be transformed for ROS)?

Fan-loewe commented 3 years ago

Sure, my pleasure!

I referred this tutorial. https://roboticsbackend.com/ros-import-python-module-from-another-package/ I first build the fast extraction C++ wrapper pose_extractor, then import the python modules into ROS.

My package is built as follows:

pose_estimation/
└── src
    └── pose_estimation
         ├── __init__.py
         ├── data
         ├── models
         ├── modules
         ├── setup.py (for pose_extractor)
         └── pose_extractor
├── CMakeLists.txt
├── package.xml
├── setup.py (for python import)
└── demo.py

With such set up of my package, "pose_estimation" need to be added as a prefix when importing the packages. For example: from pose_estimation.modules.input_reader import VideoReader, ImageReader

Extra attention is needed when importing pose_extractor (the fast version)

  1. If we want to export the python path in code, use sys.path.insert instead of sys.path.append. (I don't quite know the reason, but the latter one cannot work)
  2. In the parses_poses.py, use 'from pose_extractor import extract_poses' instead of 'from pose_estimation.pose_extractor import extract_poses'. Otherwise the model extract_poses cannot be found.

Hope it helps.

Daniil-Osokin commented 3 years ago

Many thanks for the clarifications!