GPU=1 #如果使用GPU设置为1,CPU设置为0
CUDNN=0 #如果使用CUDNN设置为1,否则为0
OPENCV=1 #如果调用摄像头,还需要设置OPENCV为1,否则为0
OPENMP=0 #如果使用OPENMP设置为1,否则为0
DEBUG=0 #如果使用DEBUG设置为1,否则为0
关于ARCH值的设置,可以到NVIDIA官网查询自身显卡的算力(https://developer.nvidia.com/cuda-gpus):
如2080TI,则为:
ARCH = -gencode arch=compute_75, code=[sm_75,compute_75]
编译:
make
编译完成后可以选择进行验证,下载训练好的模型:
wget https://pjreddie.com/media/files/yolov3.weights
运行detector:
./darknet detect cfg/yolov3.cfg yolov3.weights data/dog.jpg
wget https://pjreddie.com/media/files/darknet53.conv.74
sea_cucumber
②再来看cabin_data.data文件:
classes= 1
train = /home/pcl-02/darknet_ws/src/darknet_ros/darknet/cabin_data/data/ImageSets/Main/train.txt
valid = /home/pcl-02/darknet_ws/src/darknet_ros/darknet/cabin_data/data/ImageSets/Main/val.txt
names = cfg/cabin_name.names
backup = /home/pcl-02/darknet_ws/src/darknet_ros/darknet/cabin_data/data/weights
[net]
# Testing ### 测试模式
# batch=1
# subdivisions=1
# Training ### 训练模式,每次前向的图片数目 = batch/subdivisions
batch=64
subdivisions=16
width=416 ### 网络的输入宽、高、通道数
height=416
channels=3
momentum=0.9 ### 动量
decay=0.0005 ### 权重衰减
angle=0
saturation = 1.5 ### 饱和度
exposure = 1.5 ### 曝光度
hue=.1 ### 色调
learning_rate=0.001 ### 学习率
burn_in=1000 ### 学习率控制的参数
max_batches = 10000 ### 迭代次数
policy=steps ### 学习率策略
steps=40000,45000 ### 学习率变动步长
scales=.1,.1
[convolutional]
size=1
stride=1
pad=1
filters=18 #############
activation=linear
[yolo]
mask = 6,7,8
anchors = 10,13, 16,30, 33,23, 30,61, 62,45, 59,119, 116,90, 156,198, 373,326
classes=1 ###############
num=9
jitter=.3
ignore_thresh = .5
truth_thresh = 1
random=1 ###############
3、开始训练
./darknet detector train cfg/coco.data cfg/yolov3.cfg darknet53.conv.74 -gpus 0,1
./darknet detector train cfg/coco.data cfg/yolov3.cfg /home/pcl-02/darknet_ws/src/darknet_ros/darknet/cabin_data/data/weights/cabin_yolov3.backup -gpus 0,1
[net]
# Testing
batch=1
subdivisions=1
# Training
#batch=64
#subdivisions=16
camera_reading:
topic: /usb_cam/image_raw
queue_size: 1
yolo_model:
config_file:
name: my_yolov3.cfg
weight_file:
name: cabin_yolov3.weights
threshold:
value: 0.3
detection_classes:
names:
- sea_cucumeber
<?xml version="1.0" encoding="utf-8"?>
<launch>
<!-- Console launch prefix -->
<arg name="launch_prefix" default=""/>
<arg name="image" default="/usb_cam/image_raw" />
<!-- Config and weights folder. -->
<arg name="yolo_weights_path" default="$(find darknet_ros)/yolo_network_config/weights"/>
<arg name="yolo_config_path" default="$(find darknet_ros)/yolo_network_config/cfg"/>
<!-- ROS and network parameter files -->
<arg name="ros_param_file" default="$(find darknet_ros)/config/ros.yaml"/>
<arg name="network_param_file" default="$(find darknet_ros)/config/cabin_data.yaml"/>
<!-- Load parameters -->
<rosparam command="load" ns="darknet_ros" file="$(arg ros_param_file)"/>
<rosparam command="load" ns="darknet_ros" file="$(arg network_param_file)"/>
<!-- Start darknet and ros wrapper -->
<node pkg="darknet_ros" type="darknet_ros" name="darknet_ros" output="screen" launch-prefix="$(arg launch_prefix)">
<param name="weights_path" value="$(arg yolo_weights_path)" />
<param name="config_path" value="$(arg yolo_config_path)" />
<remap from="camera/rgb/image_raw" to="$(arg image)" />
</node>
<!--<node name="republish" type="republish" pkg="image_transport" output="screen" args="compressed in:=/front_camera/image_raw raw out:=/camera/image_raw" /> -->
</launch>
roslaunch darknet_ros cabin_darknet_ros.launch
rosbag play 6.bag
效果如下:
从效果上看,帧率很低;但从输出的yolo的log上看,帧率有60帧(使用的是双2080TI)。