Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jsk_perception] PeoplePoseEstimation2D #2115

Merged
merged 15 commits into from
Jun 24, 2017
Merged

Conversation

iory
Copy link
Member

@iory iory commented Jun 16, 2017

Add people_pose_estimation_in_2d.

people_pose_estim

@iory iory requested review from furushchev and wkentaro June 16, 2017 04:29
@iory iory changed the title Pose estim PeoplePoseEstimation2D Jun 16, 2017
@iory iory force-pushed the pose-estim branch 2 times, most recently from 8efc53e to ba459c8 Compare June 16, 2017 07:45
@iory iory changed the title PeoplePoseEstimation2D [jsk_perception] PeoplePoseEstimation2D Jun 16, 2017

pose_estimated_img, people_joint_positions = self.pose_estimate(img)
pose_estimated_msg = br.cv2_to_imgmsg(
pose_estimated_img.astype(np.uint8))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is br.cv2_to_imgmsg(..., encoding="bgr8"); fine?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fixed it

img = br.imgmsg_to_cv2(img_msg, desired_encoding='bgr8')
pose_estimated_img, people_joint_positions = self.pose_estimate(img)
pose_estimated_msg = br.cv2_to_imgmsg(
pose_estimated_img.astype(np.uint8))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -0,0 +1,2 @@
string[] limb_names
geometry_msgs/Point32[] points
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not we use geometry_msgs/Pose with nan rotation values ((0, 0, 0, 0) for quaternion),
expecting the future work of estimating rotation of human limbs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion!
Changed Point32 to Pose

@wkentaro
Copy link
Member

Anyway, this is a really nice feature 🎉

@@ -149,7 +149,7 @@ def _cb_with_depth(self, img_msg, depth_msg, camera_info_msg):

pose_estimated_img, people_joint_positions = self.pose_estimate(img)
pose_estimated_msg = br.cv2_to_imgmsg(
pose_estimated_img.astype(np.uint8))
pose_estimated_img.astype(np.uint8), encoding='bgr8')
pose_estimated_msg.header = img_msg.header
pose_estimated_msg.encoding = "bgr8"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be removed.
and same below.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what indicates 'this'? astype(np.int32)? encoding='bgr8'?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pose_estimated_msg.encoding = "bgr8"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@iory iory force-pushed the pose-estim branch 4 times, most recently from a17fe9f to 1057a8d Compare June 20, 2017 10:08
Copy link
Member

@furushchev furushchev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great feature! I'll use and would like to give you a feedback.
Please note my comment.

</rosparam>
</node>

<include file="$(find opencv_apps)/launch/hsv_color_filter.launch" >
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iory I cannot see hsv_color_filter.launch in this directory. Will you create another pull request to opencv_apps?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In opencv_apps repository, hsv_color_filter.launch exists.
https://github.com/ros-perception/opencv_apps/blob/indigo/launch/hsv_color_filter.launch

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry, thanks. It only took a lot of time to pull this repository...

@furushchev
Copy link
Member

Traceback (most recent call last):
  File "/home/demo/ros/indigo/src/jsk-ros-pkg/jsk_recognition/jsk_perception/node_scripts/people_pose_estimation_2d.py", line 504, in <module>
    PeoplePoseEstimation2D()
  File "/home/demo/ros/indigo/src/jsk-ros-pkg/jsk_common/jsk_topic_tools/src/jsk_topic_tools/transport.py", line 24, in __call__
    obj = type.__call__(cls, *args, **kwargs)
  File "/home/demo/ros/indigo/src/jsk-ros-pkg/jsk_recognition/jsk_perception/node_scripts/people_pose_estimation_2d.py", line 101, in __init__
    self._load_model()
  File "/home/demo/ros/indigo/src/jsk-ros-pkg/jsk_recognition/jsk_perception/node_scripts/people_pose_estimation_2d.py", line 109, in _load_model
    self._load_chainer_model()
  File "/home/demo/ros/indigo/src/jsk-ros-pkg/jsk_recognition/jsk_perception/node_scripts/people_pose_estimation_2d.py", line 115, in _load_chainer_model
    self.func = pickle.load(open(model_file, 'rb'))
  File "/usr/lib/python2.7/pickle.py", line 1378, in load
    return Unpickler(file).load()
  File "/usr/lib/python2.7/pickle.py", line 858, in load
    dispatch[key](self)
  File "/usr/lib/python2.7/pickle.py", line 1090, in load_global
    klass = self.find_class(module, name)
  File "/usr/lib/python2.7/pickle.py", line 1126, in find_class
    klass = getattr(mod, name)
AttributeError: 'module' object has no attribute '_recover_parameter

Something is wrong in detection node...
@iory Which version of chainer do you use?
We have currently 1.24.0 (since chainer 2.X does not support TK1 (which is cuda 6.5) any more.)

@iory
Copy link
Member Author

iory commented Jun 21, 2017

I am using chainer v2.0.0.
In chainer 1.24.0, caffe function's behavior is different.
We should change,

import chainer.links.caffe -> import chainer.functions.caffe

https://github.com/jsk-ros-pkg/jsk_recognition/pull/2115/files#diff-ecc75cd236b801b628c0107ef250fea5R11
Also, the pickled model file should be changed.
Please download following file, and change load file argument from sample launch file.
https://drive.google.com/open?id=0B_NiLAzvehC9Z0h1OGlIcDRtckU
Please try it and teach me whether you succeed.

@furushchev
Copy link
Member

@iory Thanks a lot for advice.
I download the pretrained data for v1.24 and changed files:

diff --git a/jsk_perception/node_scripts/people_pose_estimation_2d.py b/jsk_perception/node_scripts/pe
index ed23542..660e9c9 100755
--- a/jsk_perception/node_scripts/people_pose_estimation_2d.py
+++ b/jsk_perception/node_scripts/people_pose_estimation_2d.py
@@ -8,7 +8,8 @@ import pickle
 
 import chainer
 import chainer.functions as F
-import chainer.links.caffe
+#    import chainer.links.caffe
+import chainer.functions.caffe
 from chainer import cuda
 import cv2
 import matplotlib
diff --git a/jsk_perception/sample/sample_people_pose_estimation_2d.launch b/jsk_perception/sample/sam
index 76eff5d..3ef7c2e 100644
--- a/jsk_perception/sample/sample_people_pose_estimation_2d.launch
+++ b/jsk_perception/sample/sample_people_pose_estimation_2d.launch
@@ -1,7 +1,7 @@
 <launch>
 
   <arg name="gui" default="true" />
-  <arg name="GPU" default="-1" />
+  <arg name="GPU" default="0" />
   <arg name="INPUT_IMAGE" default="/camera/rgb/image_rect_color" />
   <arg name="INPUT_DEPTH_IMAGE" default="/camera/depth_registered/hw_registered/image_rect_raw" />
   <arg name="INPUT_CAMERA_INFO" default="/camera/rgb/camera_info" />
@@ -22,7 +22,7 @@
     <remap from="~input/depth" to="$(arg INPUT_DEPTH_IMAGE)" />
     <rosparam subst_value="true">
       gpu: $(arg GPU)
-      model_file: $(find jsk_perception)/trained_data/pose_estimation_2d_chainermodel.pkl
+      model_file: $(find jsk_perception)/trained_data/pose_estimation_2d_chainermodel_v1.24.pkl
       with_depth: true
       scales: [0.38]
       stride: 8

but still no luck.

[ERROR] [WallTime: 1498050794.349546] [1497924863.451970] bad callback: <bound method Subscriber.callback of <message_filters.Subscriber object at 0x7f8f101a2290>>
Traceback (most recent call last):
  File "/opt/ros/indigo/lib/python2.7/dist-packages/rospy/topics.py", line 720, in _invoke_callback
    cb(msg)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/message_filters/__init__.py", line 74, in callback
    self.signalMessage(msg)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/message_filters/__init__.py", line 56, in signalMessage
    cb(*(msg + args))
  File "/opt/ros/indigo/lib/python2.7/dist-packages/message_filters/__init__.py", line 229, in add
    self.signalMessage(*msgs)
  File "/opt/ros/indigo/lib/python2.7/dist-packages/message_filters/__init__.py", line 56, in signalMessage
    cb(*(msg + args))
  File "/home/furushchev/ros/indigo/src/jsk-ros-pkg/jsk_recognition/jsk_perception/node_scripts/people_pose_estimation_2d.py", line 154, in _cb_with_depth
    pose_estimated_img, people_joint_positions = self.pose_estimate(img)
  File "/home/furushchev/ros/indigo/src/jsk-ros-pkg/jsk_recognition/jsk_perception/node_scripts/people_pose_estimation_2d.py", line 223, in pose_estimate
    return self._pose_estimate_chainer_backend(bgr)
  File "/home/furushchev/ros/indigo/src/jsk-ros-pkg/jsk_recognition/jsk_perception/node_scripts/people_pose_estimation_2d.py", line 245, in _pose_estimate_chainer_backend
    outputs=['Mconv7_stage6_L2', 'Mconv7_stage6_L1'])
  File "/usr/local/lib/python2.7/dist-packages/chainer/links/caffe/caffe_function.py", line 193, in __call__
    output_vars = func(*input_vars)
  File "/usr/local/lib/python2.7/dist-packages/chainer/links/caffe/caffe_function.py", line 569, in __call__
    return self.caffe_func[self.name](*xs, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/chainer/links/connection/convolution_2d.py", line 109, in __call__
    deterministic=self.deterministic)
AttributeError: 'Convolution2D' object has no attribute 'deterministic'

@furushchev
Copy link
Member

With pretrained data for v1.24, it may also try to search File "/usr/local/lib/python2.7/dist-packages/chainer/links/caffe/caffe_function.py", not at functions?

@iory
Copy link
Member Author

iory commented Jun 21, 2017

It means that you cannot import chainer.functions.caffe?
In my environment,

In [1]: import chainer
In [2]: chainer.__version__
Out[2]: '1.24.0'
In [3]: import chainer.functions.caffe
In [4]:

@furushchev
Copy link
Member

furushchev commented Jun 21, 2017 via email

@iory
Copy link
Member Author

iory commented Jun 21, 2017

Sorry, try this pickle file.
https://drive.google.com/open?id=0B_NiLAzvehC9bGc4ZHRGTzRxZG8

@iory
Copy link
Member Author

iory commented Jun 21, 2017

I try in chainer v1.24.0.
We need to change a little bit code.

+++ b/jsk_perception/node_scripts/people_pose_estimation_2d.py
@@ -283,7 +283,8 @@ class PeoplePoseEstimation2D(ConnectionBasedTransport):
         all_peaks[:, 1] = peaks[:, 0]
         all_peaks[:, 2] = heatmap_avg[peaks.T.tolist()]
         peaks_order = peaks[..., 2]
-        all_peaks = all_peaks[xp.argsort(peaks_order)]
+        peaks_order = chainer.cuda.to_cpu(peaks_order)
+        all_peaks = all_peaks[np.argsort(peaks_order)]
         all_peaks[:, 3] = xp.arange(peak_counter, dtype=np.float32)
         if self.gpu != -1:
             all_peaks = chainer.cuda.to_cpu(all_peaks)

@k-okada
Copy link
Member

k-okada commented Jun 21, 2017 via email

@iory
Copy link
Member Author

iory commented Jun 21, 2017

In my opinion, we should install chainer v2.0.0 if possible since backward compatibility is broken, it is necessary to write the corresponding code one by one.
https://chainer.org/announcement/2017/06/01/released-v2.html

can we install both v1 and v2 in same environment?

I do not know what 'same' means, but if we install a virtual environment such as pyenv or anaconda, we can install v1 and v2.
But those are incompatible with ROS.

@furushchev
Copy link
Member

@iory Thanks a lot! It now works well on chainer v1.24.0

[jsk_perception][people_pose_estimation_2d.py] keep compatibility for chainer v1
@iory
Copy link
Member Author

iory commented Jun 23, 2017

@wkentaro
This sample launch file is dependent on pcl and jsk_pcl_ros.
Can I write run_depend in package.xml?

@wkentaro
Copy link
Member

wkentaro commented Jun 23, 2017

This sample launch file is dependent on pcl and jsk_pcl_ros.
Can I write run_depend in package.xml?

I prefer to remain jsk_perception independent to jsk_pcl_ros considering compilation time, so cloud you please refine the 3d processing?

@iory
Copy link
Member Author

iory commented Jun 23, 2017

Thanks! I removed pcl dependencies.

@iory
Copy link
Member Author

iory commented Jun 23, 2017

@furushchev
Please review this PR.

@furushchev
Copy link
Member

@iory Tested on my local machine. It works well. Great Job!

@iory
Copy link
Member Author

iory commented Jun 23, 2017

Travis passed. Could you merge this?

@k-okada k-okada merged commit ef9e905 into jsk-ros-pkg:master Jun 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants