yolov3 + CCTSDB (交通标志识别)——使用yolov3原始网络结构训练数据集

darknet框架的下载及配置本文不再叙述。

CCTSDB:CSUST Chinese Traffic Sign Detection Benchmark 中国交通数据集由长沙理工大学综合交通运输大数据智能处理湖南省重点实验室张建明老师团队制作完成。来源于 A Real-Time Chinese Traffic Sign Detection Algorithm Based on Modified YOLOv2一文提出的训练数据集。

论文地址:https://doi.org/10.3390/a10040127

Github:https://github.com/csust7zhangjm/CCTSDB,说明文档中有百度网盘的链接

数据集已经进行了标注,标注文件以txt文件形式保存,如下:

00000.png;527;377;555;404;warning
00001.png;738;279;815;414;prohibitory
00002.png;532;426;640;523;warning
00002.png;535;335;636;427;warning
00003.png;1175;134;1210;166;warning
00004.png;997;212;1030;244;mandatory
00005.png;276;236;311;268;mandatory
00005.png;915;217;947;248;prohibitory
00006.png;129;373;185;425;mandatory
00007.png;402;138;437;173;mandatory
00008.png;415;297;471;370;prohibitory
00009.png;343;240;375;271;mandatory
00009.png;936;220;965;249;prohibitory

数据集数据分为三类:warning,prohibitory,mandatory

标注文件中的四个整数数值表示标注框的长宽和中心点的坐标

数据图像如下:

 训练的准备过程:

为了方便,在darknet目录下创建CCTSDB目录,在CCTSDB目录下创建CCTSDB.data文件,文件内容如下:

classes=3
train=/home/btboay/桌面/yolov3-CCTSDB/darknet/CCTSDB/train.txt
names=/home/btboay/桌面/yolov3-CCTSDB/darknet/CCTSDB/CCTSDB.names
backup=/home/btboay/桌面/yolov3-CCTSDB/darknet/CCTSDB

classes代表类别数量

train后面跟一个文本文档的路径,该文档内容为训练数据的地址:

/home/btboay/桌面/yolov3-CCTSDB/CCTSDB/Images/00000~00999/00000.png
/home/btboay/桌面/yolov3-CCTSDB/CCTSDB/Images/00000~00999/00001.png
/home/btboay/桌面/yolov3-CCTSDB/CCTSDB/Images/00000~00999/00002.png
/home/btboay/桌面/yolov3-CCTSDB/CCTSDB/Images/00000~00999/00003.png
/home/btboay/桌面/yolov3-CCTSDB/CCTSDB/Images/00000~00999/00004.png
/home/btboay/桌面/yolov3-CCTSDB/CCTSDB/Images/00000~00999/00005.png
/home/btboay/桌面/yolov3-CCTSDB/CCTSDB/Images/00000~00999/00006.png
/home/btboay/桌面/yolov3-CCTSDB/CCTSDB/Images/00000~00999/00007.png
/home/btboay/桌面/yolov3-CCTSDB/CCTSDB/Images/00000~00999/00008.png
/home/btboay/桌面/yolov3-CCTSDB/CCTSDB/Images/00000~00999/00009.png

names后面跟一个文本文档的路径,该文档存放类别标签:

warning
prohibitory
mandatory

backup后跟一个目录地址,训练后的权重文件会保存到该目录下

每一个图像数据对应一个标注数据文件,这个文件是纯文本文档,内容如下:

0 527 377 555 404

第一个数字是类别编号,与上面的names文件中的类别标签顺序是相对应的,后面及标注框的大小和中心坐标,该数据最好归一化到0~1之间,收敛过程更快速,且不易引入误差。归一化可以使用原图像的大小进行缩放。

该文件与图像数据文件放在同一目录下

更改网络配置文件(yolov3.cfg):yolov3有三个yolo层,每个yolo层更改classes的值(类别数量),以及每个yolo层上面的一个卷积层的filters参数的值为(类别数量+5)*3,3种标签,filters改为24

下载预训练权重darknet53.conv.74,我们在该权重下进行训练

 

训练过程:

在darknet目录下打开终端输入:./darknet  detector  train  ./CCTSDB/CCTSDB.data  ./CCTSDB/yolov3.cfg  ./CCTSDB/darknet53.conv.74

后三个参数分别是你的data文件目录,网络配置文件目录,预训练权重目录

敲下回车开始训练,每100轮自动保存一次权重文件到backup目录下,最新的训练结果是.backup文件

当看到平均误差不再变化时,就可以停止训练了,我训练到平均误差在0.3左右停止的训练,这并不是最优的训练结果,但是因为我的显卡显存太小不支持,所以使用的云GPU主机进行的训练,5块钱一个小时,太贵了,训练了5个小时就停止了。

 

测试过程:

修改darknet/examples/darknet.c其中主函数,

else if (0 == strcmp(argv[1], "detect")){
        float thresh = find_float_arg(argc, argv, "-thresh", .5);
        char *filename = (argc > 4) ? argv[4]: 0;
        char *outfile = find_char_arg(argc, argv, "-out", 0);
        int fullscreen = find_arg(argc, argv, "-fullscreen");
        test_detector("/home/btboay/桌面/yolov3-CCTSDB/darknet/CCTSDB/CCTSDB.data", argv[2], argv[3], filename, thresh, .5, outfile, fullscreen);

将test_detector函数中前面的字符串改为你的.data文件目录

在darknet目录下,打开终端输入./darknet  detect  ./CCTSDB/yolov3.cfg  ./CCTSDB/yolov3.backup

后两个参数分别是网络配置文件地址和权重文件地址,点击回车,如下:

layer     filters    size              input                output
    0 conv     32  3 x 3 / 1   608 x 608 x   3   ->   608 x 608 x  32  0.639 BFLOPs
    1 conv     64  3 x 3 / 2   608 x 608 x  32   ->   304 x 304 x  64  3.407 BFLOPs
    2 conv     32  1 x 1 / 1   304 x 304 x  64   ->   304 x 304 x  32  0.379 BFLOPs
    3 conv     64  3 x 3 / 1   304 x 304 x  32   ->   304 x 304 x  64  3.407 BFLOPs
    4 res    1                 304 x 304 x  64   ->   304 x 304 x  64
    5 conv    128  3 x 3 / 2   304 x 304 x  64   ->   152 x 152 x 128  3.407 BFLOPs
    6 conv     64  1 x 1 / 1   152 x 152 x 128   ->   152 x 152 x  64  0.379 BFLOPs
    7 conv    128  3 x 3 / 1   152 x 152 x  64   ->   152 x 152 x 128  3.407 BFLOPs
    8 res    5                 152 x 152 x 128   ->   152 x 152 x 128
    9 conv     64  1 x 1 / 1   152 x 152 x 128   ->   152 x 152 x  64  0.379 BFLOPs
   10 conv    128  3 x 3 / 1   152 x 152 x  64   ->   152 x 152 x 128  3.407 BFLOPs
   11 res    8                 152 x 152 x 128   ->   152 x 152 x 128
   12 conv    256  3 x 3 / 2   152 x 152 x 128   ->    76 x  76 x 256  3.407 BFLOPs
   13 conv    128  1 x 1 / 1    76 x  76 x 256   ->    76 x  76 x 128  0.379 BFLOPs
   14 conv    256  3 x 3 / 1    76 x  76 x 128   ->    76 x  76 x 256  3.407 BFLOPs
   15 res   12                  76 x  76 x 256   ->    76 x  76 x 256
   16 conv    128  1 x 1 / 1    76 x  76 x 256   ->    76 x  76 x 128  0.379 BFLOPs
   17 conv    256  3 x 3 / 1    76 x  76 x 128   ->    76 x  76 x 256  3.407 BFLOPs
   18 res   15                  76 x  76 x 256   ->    76 x  76 x 256
   19 conv    128  1 x 1 / 1    76 x  76 x 256   ->    76 x  76 x 128  0.379 BFLOPs
   20 conv    256  3 x 3 / 1    76 x  76 x 128   ->    76 x  76 x 256  3.407 BFLOPs
   21 res   18                  76 x  76 x 256   ->    76 x  76 x 256
   22 conv    128  1 x 1 / 1    76 x  76 x 256   ->    76 x  76 x 128  0.379 BFLOPs
   23 conv    256  3 x 3 / 1    76 x  76 x 128   ->    76 x  76 x 256  3.407 BFLOPs
   24 res   21                  76 x  76 x 256   ->    76 x  76 x 256
   25 conv    128  1 x 1 / 1    76 x  76 x 256   ->    76 x  76 x 128  0.379 BFLOPs
   26 conv    256  3 x 3 / 1    76 x  76 x 128   ->    76 x  76 x 256  3.407 BFLOPs
   27 res   24                  76 x  76 x 256   ->    76 x  76 x 256
   28 conv    128  1 x 1 / 1    76 x  76 x 256   ->    76 x  76 x 128  0.379 BFLOPs
   29 conv    256  3 x 3 / 1    76 x  76 x 128   ->    76 x  76 x 256  3.407 BFLOPs
   30 res   27                  76 x  76 x 256   ->    76 x  76 x 256
   31 conv    128  1 x 1 / 1    76 x  76 x 256   ->    76 x  76 x 128  0.379 BFLOPs
   32 conv    256  3 x 3 / 1    76 x  76 x 128   ->    76 x  76 x 256  3.407 BFLOPs
   33 res   30                  76 x  76 x 256   ->    76 x  76 x 256
   34 conv    128  1 x 1 / 1    76 x  76 x 256   ->    76 x  76 x 128  0.379 BFLOPs
   35 conv    256  3 x 3 / 1    76 x  76 x 128   ->    76 x  76 x 256  3.407 BFLOPs
   36 res   33                  76 x  76 x 256   ->    76 x  76 x 256
   37 conv    512  3 x 3 / 2    76 x  76 x 256   ->    38 x  38 x 512  3.407 BFLOPs
   38 conv    256  1 x 1 / 1    38 x  38 x 512   ->    38 x  38 x 256  0.379 BFLOPs
   39 conv    512  3 x 3 / 1    38 x  38 x 256   ->    38 x  38 x 512  3.407 BFLOPs
   40 res   37                  38 x  38 x 512   ->    38 x  38 x 512
   41 conv    256  1 x 1 / 1    38 x  38 x 512   ->    38 x  38 x 256  0.379 BFLOPs
   42 conv    512  3 x 3 / 1    38 x  38 x 256   ->    38 x  38 x 512  3.407 BFLOPs
   43 res   40                  38 x  38 x 512   ->    38 x  38 x 512
   44 conv    256  1 x 1 / 1    38 x  38 x 512   ->    38 x  38 x 256  0.379 BFLOPs
   45 conv    512  3 x 3 / 1    38 x  38 x 256   ->    38 x  38 x 512  3.407 BFLOPs
   46 res   43                  38 x  38 x 512   ->    38 x  38 x 512
   47 conv    256  1 x 1 / 1    38 x  38 x 512   ->    38 x  38 x 256  0.379 BFLOPs
   48 conv    512  3 x 3 / 1    38 x  38 x 256   ->    38 x  38 x 512  3.407 BFLOPs
   49 res   46                  38 x  38 x 512   ->    38 x  38 x 512
   50 conv    256  1 x 1 / 1    38 x  38 x 512   ->    38 x  38 x 256  0.379 BFLOPs
   51 conv    512  3 x 3 / 1    38 x  38 x 256   ->    38 x  38 x 512  3.407 BFLOPs
   52 res   49                  38 x  38 x 512   ->    38 x  38 x 512
   53 conv    256  1 x 1 / 1    38 x  38 x 512   ->    38 x  38 x 256  0.379 BFLOPs
   54 conv    512  3 x 3 / 1    38 x  38 x 256   ->    38 x  38 x 512  3.407 BFLOPs
   55 res   52                  38 x  38 x 512   ->    38 x  38 x 512
   56 conv    256  1 x 1 / 1    38 x  38 x 512   ->    38 x  38 x 256  0.379 BFLOPs
   57 conv    512  3 x 3 / 1    38 x  38 x 256   ->    38 x  38 x 512  3.407 BFLOPs
   58 res   55                  38 x  38 x 512   ->    38 x  38 x 512
   59 conv    256  1 x 1 / 1    38 x  38 x 512   ->    38 x  38 x 256  0.379 BFLOPs
   60 conv    512  3 x 3 / 1    38 x  38 x 256   ->    38 x  38 x 512  3.407 BFLOPs
   61 res   58                  38 x  38 x 512   ->    38 x  38 x 512
   62 conv   1024  3 x 3 / 2    38 x  38 x 512   ->    19 x  19 x1024  3.407 BFLOPs
   63 conv    512  1 x 1 / 1    19 x  19 x1024   ->    19 x  19 x 512  0.379 BFLOPs
   64 conv   1024  3 x 3 / 1    19 x  19 x 512   ->    19 x  19 x1024  3.407 BFLOPs
   65 res   62                  19 x  19 x1024   ->    19 x  19 x1024
   66 conv    512  1 x 1 / 1    19 x  19 x1024   ->    19 x  19 x 512  0.379 BFLOPs
   67 conv   1024  3 x 3 / 1    19 x  19 x 512   ->    19 x  19 x1024  3.407 BFLOPs
   68 res   65                  19 x  19 x1024   ->    19 x  19 x1024
   69 conv    512  1 x 1 / 1    19 x  19 x1024   ->    19 x  19 x 512  0.379 BFLOPs
   70 conv   1024  3 x 3 / 1    19 x  19 x 512   ->    19 x  19 x1024  3.407 BFLOPs
   71 res   68                  19 x  19 x1024   ->    19 x  19 x1024
   72 conv    512  1 x 1 / 1    19 x  19 x1024   ->    19 x  19 x 512  0.379 BFLOPs
   73 conv   1024  3 x 3 / 1    19 x  19 x 512   ->    19 x  19 x1024  3.407 BFLOPs
   74 res   71                  19 x  19 x1024   ->    19 x  19 x1024
   75 conv    512  1 x 1 / 1    19 x  19 x1024   ->    19 x  19 x 512  0.379 BFLOPs
   76 conv   1024  3 x 3 / 1    19 x  19 x 512   ->    19 x  19 x1024  3.407 BFLOPs
   77 conv    512  1 x 1 / 1    19 x  19 x1024   ->    19 x  19 x 512  0.379 BFLOPs
   78 conv   1024  3 x 3 / 1    19 x  19 x 512   ->    19 x  19 x1024  3.407 BFLOPs
   79 conv    512  1 x 1 / 1    19 x  19 x1024   ->    19 x  19 x 512  0.379 BFLOPs
   80 conv   1024  3 x 3 / 1    19 x  19 x 512   ->    19 x  19 x1024  3.407 BFLOPs
   81 conv     24  1 x 1 / 1    19 x  19 x1024   ->    19 x  19 x  24  0.018 BFLOPs
   82 yolo
   83 route  79
   84 conv    256  1 x 1 / 1    19 x  19 x 512   ->    19 x  19 x 256  0.095 BFLOPs
   85 upsample            2x    19 x  19 x 256   ->    38 x  38 x 256
   86 route  85 61
   87 conv    256  1 x 1 / 1    38 x  38 x 768   ->    38 x  38 x 256  0.568 BFLOPs
   88 conv    512  3 x 3 / 1    38 x  38 x 256   ->    38 x  38 x 512  3.407 BFLOPs
   89 conv    256  1 x 1 / 1    38 x  38 x 512   ->    38 x  38 x 256  0.379 BFLOPs
   90 conv    512  3 x 3 / 1    38 x  38 x 256   ->    38 x  38 x 512  3.407 BFLOPs
   91 conv    256  1 x 1 / 1    38 x  38 x 512   ->    38 x  38 x 256  0.379 BFLOPs
   92 conv    512  3 x 3 / 1    38 x  38 x 256   ->    38 x  38 x 512  3.407 BFLOPs
   93 conv     24  1 x 1 / 1    38 x  38 x 512   ->    38 x  38 x  24  0.035 BFLOPs
   94 yolo
   95 route  91
   96 conv    128  1 x 1 / 1    38 x  38 x 256   ->    38 x  38 x 128  0.095 BFLOPs
   97 upsample            2x    38 x  38 x 128   ->    76 x  76 x 128
   98 route  97 36
   99 conv    128  1 x 1 / 1    76 x  76 x 384   ->    76 x  76 x 128  0.568 BFLOPs
  100 conv    256  3 x 3 / 1    76 x  76 x 128   ->    76 x  76 x 256  3.407 BFLOPs
  101 conv    128  1 x 1 / 1    76 x  76 x 256   ->    76 x  76 x 128  0.379 BFLOPs
  102 conv    256  3 x 3 / 1    76 x  76 x 128   ->    76 x  76 x 256  3.407 BFLOPs
  103 conv    128  1 x 1 / 1    76 x  76 x 256   ->    76 x  76 x 128  0.379 BFLOPs
  104 conv    256  3 x 3 / 1    76 x  76 x 128   ->    76 x  76 x 256  3.407 BFLOPs
  105 conv     24  1 x 1 / 1    76 x  76 x 256   ->    76 x  76 x  24  0.071 BFLOPs
  106 yolo
Loading weights from ./CCTSDB/yolov3.backup...Done!
Enter Image Path: 

输入预测图像地址,进行预测。

我的结果如下:

yolov3 + CCTSDB (交通标志识别)——使用yolov3原始网络结构训练数据集_第1张图片yolov3 + CCTSDB (交通标志识别)——使用yolov3原始网络结构训练数据集_第2张图片yolov3 + CCTSDB (交通标志识别)——使用yolov3原始网络结构训练数据集_第3张图片yolov3 + CCTSDB (交通标志识别)——使用yolov3原始网络结构训练数据集_第4张图片yolov3 + CCTSDB (交通标志识别)——使用yolov3原始网络结构训练数据集_第5张图片yolov3 + CCTSDB (交通标志识别)——使用yolov3原始网络结构训练数据集_第6张图片

 我的训练权重文件:链接: https://pan.baidu.com/s/1Yt_NhzaNq5X3a3Ho3bqftA  密码: 6ocu

 

你可能感兴趣的:(yolo)