Training of yolov3 (7) Use the darknet_ros framework for recognition and model import


###############################################
Students, don’t just follow me to operate this series of files, because This is a record of stepping on pits, not a tutorial. I just recorded the whole process, so that students in the future can avoid these pits when operating. I hope you can read the entire series of operation processes and then operate after consideration
### #################################

Use the darknet_ros framework for recognition

Then the model trained now can be used, but I want to use the ROS framework to operate

First, you need to download and install the darknet_ros feature package.
Reference file
ubuntu20 ros darknet installation record

Install feature pack

cd catkin_ws/src/
git clone --recursive git@github.com:leggedrobotics/darknet_ros.git

insert image description here
Result download failed

jetson agx xavier +darknet ros——compilation error,

re-download

cd ~/catkin_ws/src
git clone --recursive https://github.com/leggedrobotics/darknet_ros

insert image description here


Compile the darknet_ros function package separately after arriving at the workspace

cd ..
catkin_make -DCATKIN_WHITELIST_PACKAGES="darknet_ros"

insert image description here


After the compilation progresses, the recognition model yolov2-tiny.weights will be downloaded, which may be slower due to network speed
insert image description here


If you don't want to download, open the README.md file, comment or delete these download operations (not sure if this is correct)
insert image description here

recompile
insert image description here

After the compilation is complete,
if it is a new workspace, you must remember the environment variables
insert image description here

Model import darknet_ros

When darknet_ros is downloaded and compiled, we will import the trained model into

First open the [/home/heying/catkin_ws/src/darknet_ros-master/darknet_ros/config] directory

Create a new yaml configuration file, here named yolov3-voc.yaml

roscd darknet_ros/config/
touch yolov3-voc.yaml
gedit yolov3-voc.yaml

insert image description here
then edit

yolo_model:

#指定的cfg的配置文件名称
  config_file:
    name: yolov3-voc.cfg

#指定的进行识别的权重文件名称
  weight_file:
    name: yolov3-voc_5000.weights

#检测阈值的设定,只显示0.3或更高置信度检测的对象
  threshold:
    value: 0.3

#当前模型识别的类别
  detection_classes:
    names:
      - red
      - green
      - 'null'

insert image description here

#####################Attention #####################

wrong escaping of tags

It should be noted that in one of the categories [- 'null'] here, if you directly write [- null], the recognition terminal will report an error. If [- null] is placed first, you will see the following information after running the recognition in the following process
insert image description here

can be seen in

	 * /darknet_ros/yolo_model/detection_classes/names: [None, 'red', 'gr…`

This should be [null] changed to [None], which means that null may be escaped into None, causing a program error. Here is one of the pits marked in the data set

The remedy is to add single quotes to make it a character.
But the best way is not to use special characters in the labeling process, such as null, none, etc.

After adding single quotes,
run again to see that the application is correct

 * /darknet_ros/yolo_model/detection_classes/names: ['null', 'red', '...

detection type inversion

In the above, in order to facilitate the information viewing of the terminal, the positions of the detection categories in [yolov3-voc.yaml] are specially swapped, as shown in the figure
insert image description here

Then if the position is reversed and the position is not replaced again, an error will occur.
After running the recognition,
you can see that the [null] that should have been displayed is displayed as [green]. This is due to the recognition category sorting in the yaml configuration file. wrong reason
insert image description here

After modifying yaml

	#当前模型识别的类别
	  detection_classes:
	    names:
	      - red
	      - green
	      - 'null'

It can be seen that it is normal at this time
insert image description here


The basis for order judgment is during training, I think it was written during training [voc2021.names]
insert image description here


continue the process

Then the corresponding configuration file and weight file in the file are moved to /home/heying/catkin_ws/src/darknet_ros-master/darknet_ros/yolo_network_config/the corresponding file
insert image description here

Copy the generated weights file /home/heying/catkin_ws/src/darknet_ros-master/darknet_ros/yolo_network_config/weightsinto
insert image description here

Then move the yolov3-voc.cfg file used in the training process /home/heying/catkin_ws/src/darknet_ros-master/darknet_ros/yolo_network_config/cfgto
insert image description here

Open the file /home/heying/catkin_ws/src/darknet_ros-master/darknet_ros/launchin the directory yolo_v3.launch, this is the launch file we use to identify

Then modify network_param_filethe parameters and use the yaml file just written

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

insert image description here
Save and exit when done


test

Connect the camera first

Then start the camera driver

roslaunch usb_cam usb_cam-test.launch

insert image description here

Normally, the information of the camera will be called out


Then start the recognition

roslaunch darknet_ros yolo_v3.launch

insert image description here
Recognition effect
insert image description here

At this point, you can also move to view the recognition effect
insert image description here


So far, the darknet version uses yolov3 for traffic light training and recognition process.

Guess you like

Origin blog.csdn.net/Xiong2840/article/details/127937946