Shua-Kang / ros_pytorch_yolov5

23 stars 8 forks source link

When subscribe to the topic /detected_objects_in_images, return a type error. #4

Closed JiananAlvin closed 2 years ago

JiananAlvin commented 2 years ago

[ERROR] [1645192563.522846]: bad callback: <bound method detectManager.imageCb of <main.detectManager object at 0x7f065f7710>> Traceback (most recent call last): File "/workspace/pytorch_yolov5_catkin_ws/devel/lib/python3/dist-packages/ros_pytorch_yolov5/msg/_BoundingBoxes.py", line 165, in serialize buff.write(_get_struct_d4q().pack(_x.probability, _x.xmin, _x.ymin, _x.xmax, _x.ymax)) TypeError: only integer tensors of a single element can be converted to an index

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py", line 882, in publish self.impl.publish(data) File "/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py", line 1066, in publish serialize_message(b, self.seq, message) File "/opt/ros/noetic/lib/python3/dist-packages/rospy/msg.py", line 152, in serialize_message msg.serialize(b) File "/workspace/pytorch_yolov5_catkin_ws/devel/lib/python3/dist-packages/ros_pytorch_yolov5/msg/_BoundingBoxes.py", line 167, in serialize except TypeError as te: self._check_types(ValueError("%s: '%s' when writing '%s'" % (type(te), str(te), str(locals().get('_x', self))))) File "/opt/ros/noetic/lib/python3/dist-packages/genpy/message.py", line 393, in _check_types check_type(n, t, getattr(self, n)) File "/opt/ros/noetic/lib/python3/dist-packages/genpy/message.py", line 314, in check_type check_type(field_name + '[]', base_type, v) File "/opt/ros/noetic/lib/python3/dist-packages/genpy/message.py", line 324, in check_type check_type('%s.%s' % (field_name, n), t, getattr(field_val, n)) File "/opt/ros/noetic/lib/python3/dist-packages/genpy/message.py", line 273, in check_type raise SerializationError('field %s must be float type' % field_name) genpy.message.SerializationError: field bounding_boxes[].probability must be float type

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py", line 750, in _invoke_callback cb(msg) File "/workspace/pytorch_yolov5_catkin_ws/src/ros_pytorch_yolov5/yolov5/detect.py", line 120, in imageCb detections = self.detect(self.cv_image, data) File "/workspace/pytorch_yolov5_catkin_ws/src/ros_pytorchyolov5/yolov5/detect.py", line 365, in detect self.pub.publish(detection_results) File "/opt/ros/noetic/lib/python3/dist-packages/rospy/topics.py", line 886, in publish raise ROSSerializationException(str(e)) rospy.exceptions.ROSSerializationException: field bounding_boxes[].probability must be float type

JiananAlvin commented 2 years ago

Hi sorry to bother! I tried to subscribe to the topic /detected_objects_in_image, and then get such an error. BTW, I ran the whole project in docker so I can not set view_image:= True, I am trying to implement the function of show result in rviz. But when I am doing it I find such problem. I am not sure if it is for my edition of pytorch..

JiananAlvin commented 2 years ago

If I do not subscribe the topic it run perfectly. The output looks like: ######################################## 384x640 1 holes, Done. (0.051s) Done. (0.058s) 384x640 1 holes, Done. (0.052s) Done. (0.060s) 384x640 1 holes, Done. (0.055s) Done. (0.061s) 384x640 1 holes, Done. (0.054s) Done. (0.061s) 384x640 1 holes, Done. (0.053s) Done. (0.061s) 384x640 1 holes, Done. (0.054s) ###################################### I ran it in a docker with ros-neotic. Then I turned on another terminal locally and input the command rostopic echo /detected_objects_in_image. Then the problem occurred. Before that I have build and source your project both in docker and in my local env.

Shua-Kang commented 2 years ago

If I do not subscribe the topic it run perfectly. The output looks like: ######################################## 384x640 1 holes, Done. (0.051s) Done. (0.058s) 384x640 1 holes, Done. (0.052s) Done. (0.060s) 384x640 1 holes, Done. (0.055s) Done. (0.061s) 384x640 1 holes, Done. (0.054s) Done. (0.061s) 384x640 1 holes, Done. (0.053s) Done. (0.061s) 384x640 1 holes, Done. (0.054s) ###################################### I ran it in a docker with ros-neotic. Then I turned on another terminal locally and input the command rostopic echo /detected_objects_in_image. Then the problem occurred. Before that I have build and source your project both in docker and in my local env.

This image haven't be pulished. Later I will update the rviz support.

Shua-Kang commented 2 years ago

Hi sorry to bother! I tried to subscribe to the topic /detected_objects_in_image, and then get such an error. BTW, I ran the whole project in docker so I can not set view_image:= True, I am trying to implement the function of show result in rviz. But when I am doing it I find such problem. I am not sure if it is for my edition of pytorch..

Does your docker have desktop enviroment with vnc or X server? I tested it with docker image https://github.com/fcwu/docker-ubuntu-vnc-desktop. And everything is OK.

Shua-Kang commented 2 years ago

See How to build and run.md for more help.

gggdttt commented 2 years ago

See How to build and run.md for more help.

Hi! Thank you for your update and we will try it. By the way, have you tried to subscribe to the message topic /detected_objects_in_image ? I am not sure if it is for the desktop env(I think it is not)... I want to use command _rostopic echo /detected_objects_inimage to output the detection result such as "0, width,height, x_position, y_position" but it tells me "rospy.exceptions.ROSSerializationException: field bounding_boxes[].probability must be float type". The possible reason is that the first num of bounding_boxes is an integer but in msg/Boundin_boxes it is defined as float64.

Shua-Kang commented 2 years ago

screenshot-20220220-191118

Shua-Kang commented 2 years ago

See How to build and run.md for more help.

Hi! Thank you for your update and we will try it. By the way, have you tried to subscribe to the message topic /detected_objects_in_image ? I am not sure if it is for the desktop env(I think it is not)... I want to use command _rostopic echo /detected_objects_inimage to output the detection result such as "0, width,height, x_position, y_position" but it tells me "rospy.exceptions.ROSSerializationException: field bounding_boxes[].probability must be float type". The possible reason is that the first num of bounding_boxes is an integer but in msg/Boundin_boxes it is defined as float64.

I forgot to covert tensor to int and float. Let's try the new version.