darknet_ros - Aeroclub-IITM/Plugins_setup GitHub Wiki

Darknet and YOLO

Darknet is a framework to train neural networks, it is open source and written in C/CUDA and serves as the basis for YOLO. Classifying whether an image is that of a cat or a dog is one problem, detecting the cats and the dogs in your image and their locations is a different problem. While the first problem can be solved by using neural networks as classifiers, effectively determining which class an image belongs to, amongst a selection, the second problem is quite different and requires a different approach. YOLO is a powerful neural net that does exactly that: it will tell you what is in your image giving the bounding box around the detected objects.

Darknet_ros

This package helps you to detect and classify various objects in a frame.

cuda installation

Now before installing darknet_ros, you need to install cuda package to enable darknet to work on gpu because the network is computationally expensive and needs a gpu for its full potential.

https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html

Don't forget to do the post installation steps too.

https://docs.nvidia.com/deeplearning/sdk/cudnn-install/index.html

Go to this site for cudnn installation which is an effective library for deep neural networks.

If you encounter with errors like broken packages,

cudaerror

Uninstall cuda with

dpkg -l | grep cuda- | awk '{print }' | xargs -n1 sudo dpkg --purge --force-all

If you are getting warnings like this

dpkg: warning: while removing cuda-nvtx-10-2, directory '/usr/local/cuda-10.2/targets/x86_64-linux/include' not empty so not removed

dpkg: warning: while removing cuda-nvtx-10-2, directory '/usr/local/cuda-10.2/targets/x86_64-linux/lib' not empty so not removed

Then rm -rf your cuda folder, it will fix this.

Now clone the darknet_ros repo in your workspace

cd ~/catkin_ws/src

git clone --recursive https://github.com/leggedrobotics/darknet_ros.git

Now go to catkin_ws/src/darknet_ros/darknet/src , open gemm.c and change

/cudaThreadSynchronize(); to

cudaDeviceSynchronize();

darknet

catkin build -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=/usr/bin/gcc-6 to build in release mode

In the file ros.yaml specifies ros parameters. You can find this file under darknet_ros/darknet_ros/config.

You will need to change the image topic from /camera/rgb/image_raw to

/webcam/image_raw (For ardupilot if you are using iq_sim)

/iris/camera_red_iris/image_raw (For px4 users)

The file darknet_ros.launch will launch the darknet/yolo ros node. You can find this file under darknet_ros/darknet_ros/launch

in this file you can choose which version of yolo you would like to run by changing

<arg name="network_param_file" default="$(find darknet_ros)/config/yolov2-tiny.yaml"/>

the options are as follows

● yolov1: Not recommended. this model is old

● yolov2: more accurate, and faster.

● yolov3: about as fast as v2, but more accurate. Yolo v3 has a high GPU ram requirement to train and run. If your graphics card does not have enough ram,use yolo v2.

● tiny-yolo: Very fast yolo model. Would recommend for applications where speed is most important. Works very well on Nvidia Jetson.

Now roslaunch darknet_ros darknet_ros.launch will launch the node.

Darknet_ros uses unique topics to transfer data.

Rostopic list after running darknet_ros will reveal all topics.

Eg:For finding out the type of object it detected.

C++

#include <darknet_ros_msgs/BoundingBoxes.h>

void detection_cb(const darknet_ros_msgs::BoundingBoxes::ConstPtr& msg)

{

for( int i=0; i < msg->bounding_boxes.size(); i++)

{

ROS_INFO("%s detected", msg->bounding_boxes[i].Class.c_str());

}

}

ros::Subscriber sub = n.subscribe("/darknet_ros/bounding_boxes", 1, detection_cb);

Python

from darknet_ros_msgs.msg import BoundingBoxes

def callback(data):

  `mid=data.bounding_boxes[i].Class`

rospy.Subscriber("/darknet_ros/bounding_boxes", BoundingBoxes, callback)

⚠️ **GitHub.com Fallback** ⚠️