Git Product home page Git Product logo

ros_pytorch_yolov5's Introduction

Ros_pytorch_yolov5

A ROS wrapper for yolov5. (master branch is v5.0 of yolov5; for v6.1, see branch v6.1)

I have tested this repo at intel cpu and single Nvidia-GPU. Since it is just a roughly merge of yolov3_pytorch_ros and yolov5, many useless code stays. If you have any questions, feel free to create an issue.

Requirements

ROS Noetic(Recommanded) or Melodic

Running

Tracking the detection using opencv. (Rviz may be better) view_img

Quick Start

see How_to_build_and_run for more details.

Reference

yolov3_pytorch_ros

yolov5

ros_pytorch_yolov5's People

Contributors

shua-kang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ros_pytorch_yolov5's Issues

Under melodic. Build cv_bridge failed.

In your requirement.txt you install the python-opencv 4,
But when building cv_birdge, the CMakelist require opencv3
Should I install the opencv3 again?
I tried to modify the CMakeList from opencv3 to opencv4, but it seems to be incompatible.

Problems with changing the weights file

I have seen your previous reply to another questioner ,And I got this error after changing the common.py file when I was operating .If it is convenient for you, I don't know if you can make a tutorial for changing the weight of YOLOV5 v6.1 .I don't know how to proceed at the moment .Thanks for reading and looking forward to your recovery .
image

Train own weight

Hi, I already trained my own weights and changed the <arg name="weights" default="best.pt"/> in detector.launch using my own weights. but the error occur. if there anything that i need to change?

The error are as shown below

[INFO] [1672724360.280203]: start detect node [INFO] [1672724360.308326]: Launched node for object detection Load model: /home/aiman/catkin_ws_pytorch_yolov5/src/ros_pytorch_yolov5/yolov5/weights/best.pt Traceback (most recent call last): File "/home/aiman/catkin_ws_pytorch_yolov5/src/ros_pytorch_yolov5/yolov5/detect.py", line 304, in <module> dm = detectManager() File "/home/aiman/catkin_ws_pytorch_yolov5/src/ros_pytorch_yolov5/yolov5/detect.py", line 98, in __init__ self.warmup() File "/home/aiman/catkin_ws_pytorch_yolov5/src/ros_pytorch_yolov5/yolov5/detect.py", line 162, in warmup self.model = attempt_load(self.weights, map_location=self.device) # load FP32 model File "/home/aiman/catkin_ws_pytorch_yolov5/src/ros_pytorch_yolov5/yolov5/models/experimental.py", line 118, in attempt_load ckpt = torch.load(w, map_location=map_location) # load File "/home/aiman/anaconda3/lib/python3.9/site-packages/torch/serialization.py", line 592, in load return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args) File "/home/aiman/anaconda3/lib/python3.9/site-packages/torch/serialization.py", line 851, in _load result = unpickler.load() AttributeError: Can't get attribute 'MP' on <module 'models.common' from '/home/aiman/catkin_ws_pytorch_yolov5/src/ros_pytorch_yolov5/yolov5/models/common.py'> [detect_manager-1] process has died [pid 13174, exit code 1, cmd /home/aiman/catkin_ws_pytorch_yolov5/src/ros_pytorch_yolov5/yolov5/detect.py __name:=detect_manager __log:=/home/aiman/.ros/log/424d5572-8b24-11ed-84cd-b0fc36e80577/detect_manager-1.log]. log file: /home/aiman/.ros/log/424d5572-8b24-11ed-84cd-b0fc36e80577/detect_manager-1*.log [detect_manager-1] restarting process
Thank you

模型加载特别慢

我的设备是jetson agx xavier ,melodic,配置完了环境,开始运行launch文件
roslaunch ros_pytorch_yolov5 detector.launch device:=cpu view_img:=True
roslaunch ros_pytorch_yolov5 detector.launch device:=0 view_img:=True
使用cpu和gpu都试了,ros启动正常,开始detect节点后,运行完load model,执行fusing layers....
然后就没动静了,不动了,求大佬指导。

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

[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_pytorch_yolov5/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

Color problem of detection results

Hi!
When I run your program, the wrong color appears. Do you know the reason? The rgb information of the camera looks correct in rviz, but the color is reversed in yolo. I am using a realsense D455 camera.
Looking forward to your reply!
2022-06-20 17-19-44 的屏幕截图

冗余代码太多,可读性,容易产误解!

Screenshot from 2022-12-04 16-36-03
119行图片预处理函数的返回input_image并不是主要的推理函数detect()的输入。那这样预处理的作用是什么?同时经过我反复测试确定,imagePreProcessing()函数中的 input_img = resize(self.padded_image, (self.network_img_size, self.network_img_size, 3))/255.这一行操作极其耗时,在我的10代i7rtx2060上光是这一行函数执行都需要大约56ms,加上推理25ms,一帧的检测时间达到80-90ms。
同时存在大量多余的代码,读起来困难。并无冒犯之意。
还是感谢您的开源!

Error when "roslaunch ros_pytorch_yolov5 detector.launch device:=cpu view_img:=True"

May I know why this error occur?

aiman@aiman:~/catkin_ws_cv_bridge$ roslaunch ros_pytorch_yolov5 detector.launch device:=cpu view_img:=True
... logging to /home/aiman/.ros/log/13894466-7e0f-11ed-a8b6-b0fc36e80577/roslaunch-aiman-29519.log
Checking log directory for disk usage. This may take a while.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://aiman:33769/

SUMMARY

PARAMETERS

  • /detect_manager/agnostic_nms: True
  • /detect_manager/augment: True
  • /detect_manager/classes: None
  • /detect_manager/conf_thres: 0.25
  • /detect_manager/detected_objects_topic: detected_objects_...
  • /detect_manager/detections_image_topic: detections_image_...
  • /detect_manager/detections_results_topic: detections_result...
  • /detect_manager/device: cpu
  • /detect_manager/exist_ok: True
  • /detect_manager/image_topic: /usb_cam/image_raw
  • /detect_manager/img_size: 640
  • /detect_manager/iou_thres: 0.45
  • /detect_manager/name: exp
  • /detect_manager/project: runs/result
  • /detect_manager/publish_image: True
  • /detect_manager/save_conf: True
  • /detect_manager/save_txt: False
  • /detect_manager/source: data/images
  • /detect_manager/view_img: True
  • /detect_manager/weights: yolov5s.pt
  • /rosdistro: melodic
  • /rosversion: 1.14.13

NODES
/
detect_manager (ros_pytorch_yolov5/detect.py)

ROS_MASTER_URI=http://localhost:11311

process[detect_manager-1]: started with pid [29537]
Traceback (most recent call last):
File "/home/aiman/catkin_ws_pytorch_yolov5/src/ros_pytorch_yolov5/yolov5/detect.py", line 14, in
from skimage.transform import resize
File "/home/aiman/anaconda3/lib/python3.9/site-packages/skimage/init.py", line 125, in
from .util.dtype import (img_as_float32,
File "/home/aiman/anaconda3/lib/python3.9/site-packages/skimage/util/init.py", line 17, in
from ._map_array import map_array
File "/home/aiman/anaconda3/lib/python3.9/site-packages/skimage/util/_map_array.py", line 2, in
from ._remap import _map_array
File "skimage/util/_remap.pyx", line 1, in init skimage.util._remap
ValueError: numpy.ndarray size changed, may indicate binary incompatibility. Expected 88 from C header, got 80 from PyObject
[detect_manager-1] process has died [pid 29537, exit code 1, cmd /home/aiman/catkin_ws_pytorch_yolov5/src/ros_pytorch_yolov5/yolov5/detect.py __name:=detect_manager __log:=/home/aiman/.ros/log/13894466-7e0f-11ed-a8b6-b0fc36e80577/detect_manager-1.log].
log file: /home/aiman/.ros/log/13894466-7e0f-11ed-a8b6-b0fc36e80577/detect_manager-1*.log

Can't reproduce

Hello, I used your project, but there is no picture. Can you tell me more specifically? Thank you for your help. If you can, you can communicate via email. My email is [email protected]

bad call

Hello! My English is not very good. I encountered a bad call problem when using d435i. I modified the camera resolution and topic name. Have you encountered it? How can I modify model and data? thank you.
Screenshot from 2022-06-05 20-51-49
Screenshot from 2022-06-05 20-51-49

Choosing between different model types

Hi!
I have been trying to understand the wrapper's working and can't seem to find how to choose a model type. We want to use yolov5n(nano) and don't know what the default config is. Any help regarding how to choose a model would be great. Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.