###############################################
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
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
Compile the darknet_ros function package separately after arriving at the workspace
cd ..
catkin_make -DCATKIN_WHITELIST_PACKAGES="darknet_ros"
After the compilation progresses, the recognition model yolov2-tiny.weights will be downloaded, which may be slower due to network speed
If you don't want to download, open the README.md file, comment or delete these download operations (not sure if this is correct)
recompile
After the compilation is complete,
if it is a new workspace, you must remember the environment variables
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
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'
#####################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
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
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
After modifying yaml
#当前模型识别的类别
detection_classes:
names:
- red
- green
- 'null'
It can be seen that it is normal at this time
The basis for order judgment is during training, I think it was written during training [voc2021.names]
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
Copy the generated weights file /home/heying/catkin_ws/src/darknet_ros-master/darknet_ros/yolo_network_config/weights
into
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/cfg
to
Open the file /home/heying/catkin_ws/src/darknet_ros-master/darknet_ros/launch
in the directory yolo_v3.launch
, this is the launch file we use to identify
Then modify network_param_file
the parameters and use the yaml file just written
<arg name="network_param_file" default="$(find darknet_ros)/config/yolov3-voc.yaml"/>
Save and exit when done
test
Connect the camera first
Then start the camera driver
roslaunch usb_cam usb_cam-test.launch
Normally, the information of the camera will be called out
Then start the recognition
roslaunch darknet_ros yolo_v3.launch
Recognition effect
At this point, you can also move to view the recognition effect
So far, the darknet version uses yolov3 for traffic light training and recognition process.