I want to implement a yolov5 algorithm to a ROS2
subscriber. But it claims that yolov5 not found.
$ ros2 run yolov5_detect webcam_yolo_sub
Traceback (most recent call last):
File "/home/jun/ros2_guyue/colcon_ws/install/yolov5_detect/lib/yolov5_detect/webcam_yolo_sub", line 33, in <module>
sys.exit(load_entry_point('yolov5-detect==0.0.0', 'console_scripts', 'webcam_yolo_sub')())
File "/home/jun/ros2_guyue/colcon_ws/install/yolov5_detect/lib/yolov5_detect/webcam_yolo_sub", line 25, in importlib_load_entry_point
return next(matches).load()
File "/usr/lib/python3.8/importlib/metadata.py", line 77, in load
module = import_module(match.group('module'))
File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 848, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/jun/ros2_guyue/colcon_ws/install/yolov5_detect/lib/python3.8/site-packages/yolov5_detect/webcam_yolo_sub.py", line 12, in <module>
from yolov5 import detect_ros
ModuleNotFoundError: No module named 'yolov5'
I have rewritten the detector
as a class and have successfully launched in ROS1 noetic.
Basing on the error message above, I think it maybe because for ROS1 the .py script is exactly the executable file of $ rosrun <pkg_name> <node_name>
, while for ROS2 the file to be run is generated in /workspace/install
, therefore the yolov5 folder cannot link to the executable file correctly.
My question is: how to implement an algorithm from outside in ROS2 framework?
Click to check my code on github
Thanks :D