Giter VIP home page Giter VIP logo

yolov4_trt_ros's Introduction

YOLOv4 with TensorRT engine

This package contains the yolov4_trt_node that performs the inference using NVIDIA's TensorRT engine

This package works for both YOLOv3 and YOLOv4. Do change the commands accordingly, corresponding to the YOLO model used.

Video_Result2


Setting up the environment

Install dependencies

Current Environment:

  • Jetson Xavier AGX
  • ROS Melodic
  • Ubuntu 18.04
  • Jetpack 4.4
  • TensorRT 7+

Dependencies:

  • OpenCV 3.x
  • numpy 1.15.1
  • Protobuf 3.8.0
  • Pycuda 2019.1.2
  • onnx 1.4.1 (depends on Protobuf)

Install all dependencies with below commands

Install pycuda (takes awhile)
$ cd ${HOME}/catkin_ws/src/yolov4_trt_ros/dependencies
$ ./install_pycuda.sh

Install Protobuf (takes awhile)
$ cd ${HOME}/catkin_ws/src/yolov4_trt_ros/dependencies
$ ./install_protobuf-3.8.0.sh

Install onnx (depends on Protobuf above)
$ sudo pip3 install onnx==1.4.1
  • Please also install jetson-inference
  • Note: This package uses similar nodes to ros_deep_learning package. Please place a CATKIN_IGNORE in that package to avoid similar node name catkin_make error
  • If these scripts do not work for you, do refer to this amazing repository by jefflgaol on installing the above packages and more on Jetson ARM devices.

Setting up the package

1. Clone project into catkin_ws and build it

$ cd ~/catkin_ws && catkin_make
$ source devel/setup.bash

2. Make libyolo_layer.so

$ cd ${HOME}/catkin_ws/src/yolov4_trt_ros/plugins
$ make

This will generate a libyolo_layer.so file

3. Place your yolo.weights and yolo.cfg file in the yolo folder

$ cd ${HOME}/catkin_ws/src/yolov4_trt_ros/yolo

** Please name the yolov4.weights and yolov4.cfg file as follows:

  • yolov4.weights
  • yolov4.cfg

Run the conversion script to convert to TensorRT engine file

$ ./convert_yolo_trt
  • Input the appropriate arguments
  • This conversion might take awhile
  • The optimised TensorRT engine would now be saved as yolov3-416.trt / yolov4-416.trt

4. Change the class labels

$ cd ${HOME}/catkin_ws/src/yolov4_trt_ros/utils
$ vim yolo_classes.py
  • Change the class labels to suit your model

5. Change the video_input and topic_name

$ cd ${HOME}/catkin_ws/src/yolov4_trt_ros/launch
  • yolov3_trt.launch : change the topic_name

  • yolov4_trt.launch : change the topic_name

  • video_source.launch : change the input format (refer to this Link

    • video_source.launch requires jetson-inference to be installed
    • Default input is CSI camera

Using the package

Running the package

Note: Run the launch files separately in different terminals

1. Run the video_source

# For csi input
$ roslaunch yolov4_trt_ros video_source.launch input:=csi://0

# For video input
$ roslaunch yolov4_trt_ros video_source.launch input:=/path_to_video/video.mp4

# For USB camera
$ roslaunch yolov4_trt_ros video_source.launch input:=v4l2://0

2. Run the yolo detector

# For YOLOv3 (single input)
$ roslaunch yolov4_trt_ros yolov3_trt.launch

# For YOLOv4 (single input)
$ roslaunch yolov4_trt_ros yolov4_trt.launch

# For YOLOv4 (multiple input)
$ roslaunch yolov4_trt_ros yolov4_trt_batch.launch

3. For maximum performance

$ cd /usr/bin/
$ sudo ./nvpmodel -m 0	# Enable 2 Denver CPU
$ sudo ./jetson_clock	# Maximise CPU/GPU performance
  • These commands are found/referred in this forum post
  • Please ensure the jetson device is cooled appropriately to prevent overheating

Parameters

  • str model = "yolov3" or "yolov4"

  • str model_path = "/abs_path_to_model/"

  • int input_shape = 288/416/608

  • int category_num = 80

  • double conf_th = 0.5

  • bool show_img = True

  • Default Input FPS from CSI camera = 30.0

  • To change this, go to jetson-inference/utils/camera/gstCamera.cpp
# In line 359, change this line
mOptions.frameRate = 15

# To desired frame_rate
mOptions.frameRate = desired_frame_rate

Results obtained

Inference Results

Single Camera Input

Model Hardware FPS Inference Time (ms)
Yolov4-416 Xavier AGX 40.0 0.025
Yolov4-416 Jetson Tx2 16.0 0.0625
  • Will be adding inference tests for YOLOv3/4 and YOLOv3-tiny/YOLOv4-tiny for different Jetson devices and multiple camera inputs inference tests in the future

1. Screenshots

Video_in: .mp4 video (640x360)

Tests Done on Xavier AGX

Avg FPS : ~38 FPS

Video_Result1

Video_Result2

Video_Result3


Licenses and References

1. TensorRT samples from jkjung-avt

Many thanks for his project with tensorrt samples. I have referenced his source code and adapted it to ROS for robotics applications.

I also used the pycuda and protobuf installation script from his project

Those code are under MIT License

2. Jetson-inference from dusty-nv

Many thanks for his work on the Jetson Inference with ROS. I have used his video_source input from his project for capturing video inputs.

Those code are under NVIDIA License

yolov4_trt_ros's People

Contributors

indra4837 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar

yolov4_trt_ros's Issues

For help on ros message

I am using your code on the robot and it is currently running normally. I have two questions that need your help:

    1. The ros message needs to be sent when the target is detected, instead of sending it all the time.
      My goal is only one class of 'person'. Only when a person is detected, I need to send a message. I only need to publish a simple message like 'stop' to another node to receive it to control the robot's walking. How should I modify Code.
  1. I run on jetson nano, so I tend to use yolov3-ting or yolov4-tiny. Can you add these two models?
    Thank you for any help and look forward to receiving your reply. Thank you.
    @indra4837

object has no attribute'allocate_buffers'

I met some problem and i can't solve it.

i have two solve direction.
My python have error. My python version is 3.6.9
Cuda doesn't clear completely.

If i get some help, i will appreciate .

`PARAMETERS

  • /rosdistro: melodic
  • /rosversion: 1.14.13
  • /yolov4_trt_node/category_number: 10
  • /yolov4_trt_node/confidence_threshold: 0.5
  • /yolov4_trt_node/input_shape: 416
  • /yolov4_trt_node/model: yolov4
  • /yolov4_trt_node/model_path: /home/jetson/catk...
  • /yolov4_trt_node/show_image: True
  • /yolov4_trt_node/video_topic: /video_source/raw

NODES
/
yolov4_trt_node (yolov4_trt_ros/trt_yolo_v4.py)

auto-starting new master
process[master]: started with pid [15199]
ROS_MASTER_URI=http://localhost:11311

setting /run_id to 291d39c4-29d0-11ed-b07f-60a4b7c96821
process[rosout-1]: started with pid [15212]
started core service [/rosout]
process[yolov4_trt_node-2]: started with pid [15215]
Traceback (most recent call last):
File "/home/jetson/catkin_ws/src/yolov4_trt_ros/trt_yolo_v4.py", line 175, in
main()
File "/home/jetson/catkin_ws/src/yolov4_trt_ros/trt_yolo_v4.py", line 164, in main
yolo = yolov4()
File "/home/jetson/catkin_ws/src/yolov4_trt_ros/trt_yolo_v4.py", line 35, in init
(self.model_path + self.model), (self.h, self.w), self.category_num)
File "/home/jetson/catkin_ws/src/yolov4_trt_ros/utils/yolo_with_plugins.py", line 221, in init
self.inputs, self.outputs, self.bindings, self.stream ,grid_sizes= self.allocate_buffers(self.engine, grid_sizes)
AttributeError: 'TrtYOLO' object has no attribute 'allocate_buffers'

PyCUDA ERROR: The context stack was not empty upon module cleanup.

A context was still active when the context stack was being
cleaned up. At this point in our execution, CUDA may already
have been deinitialized, so there is no way we can finish
cleanly. The program will be aborted now.
Use Context.pop() to avoid this problem.
`

USB camera

Hello,

Can you help me to correct this error,
I use a USB camera as input.
roslaunch yolov4_trt_ros video_source.launch input:=v4l2://3
RLException: [video_source.launch] is neither a launch file in package [yolov4_trt_ros] nor is [yolov4_trt_ros] a launch file name
The traceback for the exception was written to the log file

Regards
Minion 40

compatibility with tensor rt8

thanks for such a efficient work but when I run on my system ;
Nvidia Xavier AGX
Jetpack 4.6
Cuda 10.2
Tensor rt8

It throws out error as below
image

Any idea to fix it?

small question

Hello,

I put th commande
./convert_yolo_trt.sh
YOLOv3 or YOLOv4. Input 3 or 4
4
Do you want to download the model? [Y/N]
y
What is the input shape? Input 288 or 416 or 608
416
Creating yolov4-416.cfg and yolov4-416.weights
How many categories are there?
An d i have this question What should be done ?
thank you for your help
Regards
Minion40

Complet readme file

Hello,

In the part 3,after the "cd" command ,add the download command : "./download_yolo.sh"

Best regards
Minion40

something went wrong when I run roslaunch

nvidia@nvidia-desktop:~$ roslaunch yolov4_trt_ros yolov4_trt.launch
... logging to /home/nvidia/.ros/log/c52fbab6-92fa-11ec-9d08-48b02d15fa07/roslaunch-nvidia-desktop-14376.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://nvidia-desktop:35351/

SUMMARY

PARAMETERS

  • /rosdistro: melodic
  • /rosversion: 1.14.12
  • /yolov4_trt_node/category_number: 3
  • /yolov4_trt_node/confidence_threshold: 0.5
  • /yolov4_trt_node/input_shape: 416
  • /yolov4_trt_node/model: yolov4-tiny
  • /yolov4_trt_node/model_path: /home/nvidia/vola...
  • /yolov4_trt_node/show_image: True
  • /yolov4_trt_node/video_topic: /video_source/raw

NODES
/
yolov4_trt_node (yolov4_trt_ros/trt_yolo_v4.py)

ROS_MASTER_URI=http://localhost:11311

process[yolov4_trt_node-1]: started with pid [14393]
Traceback (most recent call last):
File "/home/nvidia/volansjiahang/src/mid/image_process/yolov4_trt_ros/trt_yolo_v4.py", line 173, in
main()
File "/home/nvidia/volansjiahang/src/mid/image_process/yolov4_trt_ros/trt_yolo_v4.py", line 163, in main
yolo = yolov4()
File "/home/nvidia/volansjiahang/src/mid/image_process/yolov4_trt_ros/trt_yolo_v4.py", line 33, in init
(self.model_path + self.model), (self.h, self.w), self.category_num)
File "/home/nvidia/volansjiahang/src/mid/image_process/yolov4_trt_ros/utils/yolo_with_plugins.py", line 220, in init
self.engine, grid_sizes)
File "/home/nvidia/volansjiahang/src/mid/image_process/yolov4_trt_ros/utils/yolo_with_plugins.py", line 258, in allocate_buffers
3 * 7 * engine.max_batch_size
AssertionError
Exception ignored in: <bound method TrtYOLO.del of <utils.yolo_with_plugins.TrtYOLO object at 0x7f8cb90f28>>
Traceback (most recent call last):
File "/home/nvidia/volansjiahang/src/mid/image_process/yolov4_trt_ros/utils/yolo_with_plugins.py", line 224, in del
del self.outputs
AttributeError: outputs

PyCUDA ERROR: The context stack was not empty upon module cleanup.

A context was still active when the context stack was being
cleaned up. At this point in our execution, CUDA may already
have been deinitialized, so there is no way we can finish
cleanly. The program will be aborted now.
Use Context.pop() to avoid this problem.

[yolov4_trt_node-1] process has died [pid 14393, exit code -6, cmd /home/nvidia/volansjiahang/src/mid/image_process/yolov4_trt_ros/trt_yolo_v4.py __name:=yolov4_trt_node __log:=/home/nvidia/.ros/log/c52fbab6-92fa-11ec-9d08-48b02d15fa07/yolov4_trt_node-1.log].
log file: /home/nvidia/.ros/log/c52fbab6-92fa-11ec-9d08-48b02d15fa07/yolov4_trt_node-1*.log
all processes on machine have died, roslaunch will exit
shutting down processing monitor...
... shutting down processing monitor complete
done

Issue with yolo_layer.cu

Hi!

First of all, thanks a lot for your hard work on this great package!

I get an error when launching the launch file yolov3_trt.launch:
python3: yolo_layer.cu:71: nvinfer1::YoloLayerPlugin::YoloLayerPlugin(const void*, size_t): Assertion d == a + length' failed.

This is quite strange as I can see yolo_layer.cu comes from JK Jung's package and I was able to run his package with the same setup:

  • Ubuntu 18.04
  • ROS Melodic
  • TensorRT 7.1.3.0
  • Cuda 10.2
  • OpenCV 4.2.0
  • Pycuda 2019.1.2

Any idea what could be the cause of this issue?

Thanks a lot!

[ERROR] [1636165170.171413]: bad callback: <bound method yolov4.img_callback of <__main__.yolov4 object at 0x7fa52a9910>

Hello, I ran into a problem as shown below:
I need your help, thank you very much

[ERROR] [1636165170.171413]: bad callback: <bound method yolov4.img_callback of <__main__.yolov4 object at 0x7fa52a9910>> Traceback (most recent call last): File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/topics.py", line 750, in _invoke_callback cb(msg) File "/home/nvidia-yolov4/yolo_ros_trt/src/yolov4_trt_ros/trt_yolo_v4.py", line 112, in img_callback self.publisher(boxes, confs, clss) File "/home/nvidia-yolov4/yolo_ros_trt/src/yolov4_trt_ros/trt_yolo_v4.py", line 138, in publisher detection2d.header.stamp = rospy.Time.now() File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/rostime.py", line 155, in now return get_rostime() File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/rostime.py", line 190, in get_rostime raise rospy.exceptions.ROSInitException("time is not initialized. Have you called init_node()?") ROSInitException: time is not initialized. Have you called init_node()?

image

error while running the "roslaunch yolov4_trt_ros yolov4_trt.launch", Ros melodic and python3 compatibility issues

How to run python3 files with ros melodic as Ros melodic is purely based on python2.7.

I get this error while running "roslaunch yolov4_trt_ros yolov4_trt.launch", here is the error

Traceback (most recent call last):
File "/home/catkin_ws/src/yolov4_trt_ros/trt_yolo_v4.py", line 6, in
import cv2
File "/usr/lib/python3.6/dist-packages/cv2/init.py", line 89, in
bootstrap()
File "/usr/lib/python3.6/dist-packages/cv2/init.py", line 62, in bootstrap
], True)
File "/usr/lib/python3.6/dist-packages/cv2/init.py", line 56, in load_first_config
raise ImportError('OpenCV loader: missing configuration file: {}. Check OpenCV installation.'.format(fnames))
ImportError: OpenCV loader: missing configuration file: ['config-2.7.py', 'config-2.py']. Check OpenCV installation.
[yolov4_trt_node-1] process has died [pid 11630, exit code 1, cmd /home/catkin_ws/src/yolov4_trt_ros/trt_yolo_v4.py __name:=yolov4_trt_node __log:=/home/.ros/log/a39fb3ce-626c-11ec-a693-eae4f550af8b/yolov4_trt_node-1.log].
log file: /home/.ros/log/a39fb3ce-626c-11ec-a693-eae4f550af8b/yolov4_trt_node-1*.log

having a problem while running the node

Hello,
Im having the following problem while running the node:
Screenshot from 2021-01-28 21-24-04

Im using Jetson Xavier and trying to run yolov4 with video from my ZED2 camera.
the error is
ImportError: /home/greensail/cv_ws/devel/lib/python2.7/dist-packages/cv_bridge/boost/cv_bridge_boost.so: undefined symbol: _ZTIN5boost6python7objects21py_function_impl_baseE

Strange bounding boxes when batch processing

Hi!

I'm currently working on an object detection pipeline using yolov3. As the pipeline takes inputs from several cameras, I was thinking of using your trt_yolo_v4_batch.py script.

I tried it out with a yolov3-416 object detector and everything worked great. However, with yolov3-tiny-416, I am getting a weird behaviour. It seems like bounding boxes of a certain image are displayed on several image streams simultaneously.

For example, in the following gif, you can see that a bounding box is correctly displayed on the /detection_image/right image stream but the same bounding box is also displayed on the /detection_image/front image stream. I added a frame where this issue occurs.

Do you know what could be the issue here ?

gif

frame of interest

Thanks a lot for your time!

Something about the yolov4 can't work with a mp4 file or USB cam

Hello,
Thank you for your looking my question in your busy schedule!

Platform: Jetson Nano
Ros-melodic
Ubuntu 18.04 based on arm
cv_bridge based on python3.6

I got a yolov4-416.trt Model using the ./download_yolo.sh and convert_yolo_trt.sh

Then I test the program with the command:

  1. roslaunch yolov4_trt_ros video_source.launch input:=/home/nvidia/oversize.mp4
  2. roslaunch yolov4_trt_ros yolov4_trt.launch

But with the process on, there is no output label or boxes results in the detection window YOLOv4 DETECTION RESULTS
you can see the image results as follow:
Screenshot from 2021-04-24 02-22-25

I am looking forward to your reply as soon as possible,thank you very much!

Issues Running ./convert_yolo_trt.sh

Hello, I am trying to setup yolo on my jetson nano.
I am very new to everything so i apologize if anything is unclear.

Right now I am running using the Jetpack 4.6.1, it seems like the only difference between our two implementations is the jetpack 4.6.1 comes with TensorRT 8.0.1, I already know that is impossible to downgrade to TensorRT 7 without downgrading the jetpack.

Everything runs in the covert_yolo_trt script until it runs the python script onnx_to_tensorrt.py.

I was wondering if there was a implementation of this onnx to tensorrt script for TensortRT 8.0.1, as it seems the script is having issues running on my version of TensortRT, thank you for any help!

Cannot lanuch node of type

Hi Indra,

I am trying to run the same code in Xavier Nx.

When I try to run the final step, I get this error. Could you please help, where I am going wrong ?

thukhi@thukhi:~/catkin_ws/src/yolov4_trt_ros/launch$ roslaunch yolov4_trt_ros video_source.launch input:=file://sample.mp4
... logging to /home/thukhi/.ros/log/5e690190-b5db-11eb-b791-ec2e987b94d7/roslaunch-thukhi-16599.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://thukhi:35395/

SUMMARY
========

PARAMETERS
 * /rosdistro: melodic
 * /rosversion: 1.14.10
 * /video_source/height: 360
 * /video_source/loop: 0
 * /video_source/resource: file://sample.mp4
 * /video_source/width: 640

NODES
  /
    video_source (yolov4_trt_ros/video_source)

auto-starting new master
process[master]: started with pid [16609]
ROS_MASTER_URI=http://localhost:11311

setting /run_id to 5e690190-b5db-11eb-b791-ec2e987b94d7
process[rosout-1]: started with pid [16620]
started core service [/rosout]
ERROR: cannot launch node of type [yolov4_trt_ros/video_source]: Cannot locate node of type [video_source] in package [yolov4_trt_ros]. Make sure file exists in package path and permission is set to executable (chmod +x)
^C[rosout-1] killing on exit
^C[master] killing on exit
^Cshutting down processing monitor...
... shutting down processing monitor complete
done

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.