【darknet】2、yolov4模型训练之模型训练

2023-10-26

文章目录


本文是继上一篇 数据准备之后,进行模型训练的全流程。本文直接从jupter notebook转换而来,都经过验证,但格式可能会有点问题。

1、进行模型训练数据准备

使用的数据集是VOC2007_DEST,VOC2012_DEST,COCO_VOC_DEST,分类是bicycle,bus,car,motorbike,truck五个分类,将使用darknet,这些个分类的来源,请查看本节其它的jupyter

1.1 划分训练和验证集

import os

def create_train_val(datasets=[("VOC2007_DEST",1.0),("VOC2012_DEST",1.0),("COCO_VOC_DEST",0.95)]):

    wd = os.getcwd()
    for dataset,percent in datasets:
        img_files = os.listdir('%s/VOCdevkit/%s/JPEGImages' %(wd,dataset))
        split = int(len(img_files) * percent)
        train_img_files,val_img_files = img_files[:split],img_files[split:]
        with open('%s/VOCdevkit/%s/ImageSets/Main/train.txt' %(wd,dataset),'w') as f1:
            for img_file in train_img_files:
                f1.write(img_file.split('.')[0]+'\n')
        print('train.txt done')
        with open('%s/VOCdevkit/%s/ImageSets/Main/val.txt' %(wd,dataset),'w') as f2:
            for img_file in val_img_files:
                f2.write(img_file.split('.')[0]+'\n')
        print('val.txt done')
create_train_val()

本代码支持多个VOC格式数据集的合并。数据的划分没有打散等操作,也可以使用skleran.model_select.train_test_split来划分。
如下:

import os
from sklearn.model_selection import train_test_split

def create_train_val(datasets=[("VOC2007_DEST",1.0),("VOC2012_DEST",1.0),("COCO_VOC_DEST",0.95)]):

    wd = os.getcwd()
    for dataset,percent in datasets:
        img_files = os.listdir('%s/VOCdevkit/%s/JPEGImages' %(wd,dataset))
        if percent<1.0:
            train_img_files,val_img_files = train_test_split(img_files,train_size=percent,random_state=42)
        else:
            train_img_files,val_img_files=img_files,[]
        with open('%s/VOCdevkit/%s/ImageSets/Main/train.txt' %(wd,dataset),'w') as f1:
            for img_file in train_img_files:
                f1.write(img_file.split('.')[0]+'\n')
        print('train.txt done')
        with open('%s/VOCdevkit/%s/ImageSets/Main/val.txt' %(wd,dataset),'w') as f2:
            for img_file in val_img_files:
                f2.write(img_file.split('.')[0]+'\n')
        print('val.txt done')

1.2 将数据标注格式转换为YOLO格式

import os
import shutil
from tqdm import tqdm
import xml.etree.ElementTree as ET
def convert(size, box):
    dw = 1./size[0]
    dh = 1./size[1]
    x = (box[0] + box[1])/2.0
    y = (box[2] + box[3])/2.0
    w = box[1] - box[0]
    h = box[3] - box[2]
    x = x*dw
    w = w*dw
    y = y*dh
    h = h*dh
    return (x,y,w,h)

def convert_yolo(datasets=[('VOC2007_DEST','train'),('VOC2007_DEST','val')],classes=['bicycle','bus','car','motorbike','truck']):
    wd = os.getcwd()
    #直接把原有结果全部清理
    for i,(dataset, image_set) in enumerate(datasets):
        dest_path = 'VOCdevkit/%s/labels/'%(dataset)

        if os.path.exists(dest_path):
            shutil.rmtree(dest_path)
    #重新生成新的数据集
    for i,(dataset, image_set) in enumerate(datasets):
        dest_path = 'VOCdevkit/%s/labels/'%(dataset)
        if not os.path.exists(dest_path):
            os.makedirs(dest_path)
    for i,(dataset, image_set) in tqdm(enumerate(datasets)):
        image_ids = open('VOCdevkit/%s/ImageSets/Main/%s.txt'%(dataset, image_set)).read().strip().split()
        list_file = open('%s_%s.txt'%(dataset, image_set), 'w')
        for image_id in image_ids:
            list_file.write('%s/VOCdevkit/%s/JPEGImages/%s.jpg\n'%(wd, dataset, image_id))
            try: #对于有标记文件的数据可以进行转换
                in_file = open('VOCdevkit/%s/Annotations/%s.xml'%(dataset, image_id))
                out_file = open('VOCdevkit/%s/labels/%s.txt'%(dataset, image_id), 'w')
                tree=ET.parse(in_file)
                root = tree.getroot()
                size = root.find('size')
                # print image_id
                w = int(size.find('width').text)
                h = int(size.find('height').text)

                for obj in root.iter('object'):
                    difficult = obj.find('difficult').text
                    cls = obj.find('name').text
                    if cls not in classes or int(difficult) == 1:
                        continue
                    cls_id = classes.index(cls)
                    xmlbox = obj.find('bndbox')
                    b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text), float(xmlbox.find('ymax').text))
                    bb = convert((w,h),b)
                    out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')
                out_file.close()
            except:#对没有标记的图片,称为背景图片,则产生的yolo标注文件是空的即可
                out_file = open('VOCdevkit/%s/labels/%s.txt'%(dataset, image_id), 'w')

                out_file.close()

        list_file.close()
    train_txt=[a+'_'+b+'.txt' for a,b in datasets if b=='train']
    if len(train_txt):
        strs_train = 'cat '+ ' '.join(train_txt) +' > cfg/train.txt'
        os.system(strs_train)
    val_txt = [a+'_'+b+'.txt' for a,b in datasets if b=='val']
    if len(val_txt):
        strs_val = 'cat '+ ' '.join(val_txt) +'> cfg/val.txt'    
        os.system(strs_val)
    train_val_txt = [a+'_'+b+'.txt' for a,b in datasets]
    if len(train_val_txt):
        rm_txt = 'rm '+ ' '.join(train_val_txt)
        os.system(rm_txt)
    print("all Done!")

convert_yolo(datasets=[('VOC2007_DEST','train'),('VOC2007_DEST','val'),('VOC2012_DEST','train'),('VOC2012_DEST','val'),('COCO_VOC_DEST','train'),('COCO_VOC_DEST','val')],classes=['bicycle','bus','car','motorbike','truck'])
# convert_yolo()
6it [00:04,  1.24it/s]

all Done!
! ls VOCdevkit/VOC2012_DEST/labels

以上转换相对于原来darknet的转换脚本做了一点小改动,可以对有标注文件但没有标注框的标注文件进行转换。

2、修改配置文件

本次配置将使用多种模型,具体看下文:

2.1 新建cfg/vechle.names

vechle.names中存放我们要进行的分类,注意顺序

names = ['bicycle','bus','car','motorbike','truck']
with open('cfg/vechcle.names','w') as f:
    for i,name in enumerate(names):
        f.write(name)
        if i != len(names)-1:
            f.write('\n')
with open('cfg/vechcle.names') as f:
    print(f.read())
bicycle
bus
car
motorbike
truck

2.2 新建cfg/vechle.data

可以复制datknet cfg/voc.data再根据自己的情况进行修改

datas=["classes= 5",
"train  = /workspace/yolo_demo/cfg/train.txt",
"valid  = /workspace/yolo_demo/cfg/val.txt",
"names = /workspace/yolo_demo/cfg/vechcle.names",
"backup = /workspace/yolo_demo/backup"
]
with open('cfg/vechcle.data','w') as f:
    for i,data in enumerate(datas):
        f.write(data)
        if i != len(datas)-1:
            f.write('\n')
with open('cfg/vechcle.data') as f:
    print(f.read())
classes= 5
train  = /workspace/yolo_demo/cfg/train.txt
valid  = /workspace/yolo_demo/cfg/val.txt
names = /workspace/yolo_demo/cfg/vechcle.names
backup = /workspace/yolo_demo/backup

2.3 根据所选模型的不同,设置不同的配置文件

在这里插入图片描述

上图为不同模型的对比结果。下面将列出不同模型的在MSCOCO数据集上的预训练模型及相关说明,FPS是在 RTX 2070 ® 或 Tesla V100 (V)上的结果

配置文件 输入大小 mAP@0.5 mAP@0.5:0.95 FPS 大小 预训练模型
yolov4-p6.cfg 1280x1280 72.1% 54.0% 32(V) 487MB yolov4-p6.conv.289
yolov4-p5.cfg 896x896 10.0% 51.6% 43(V) 271MB yolov4-p5.conv.232
yolov4-csp-x-swish.cfg 640x640 69.9% 51.5% 23®50(V) 381MB yolov4-csp-x-swish.conv.192
yolov4-csp-swish.cfg 640x640 68.7% 50% 70(V) 202M yolov4-csp-swish.conv.164
yolov4x-mish.cfg 640x640 68.5% 50.1% 23®50(V) 381M yolov4x-mish.conv.166
yolov4-csp.cfg 640x640 67.4% 48.7% 70(V) 202M yolov4-csp.conv.142
yolov4-csp.cfg 512x512 64.8% 46.2% 93(V) 202M yolov4-csp.conv.142
yolov4.cfg 608x608 65.7% 43.5% 34®64(V) 245M yolov4.conv.137
yolov4.cfg 512x512 64.9% 43.0% 45®83(V) 245M yolov4.conv.137
yolov4.cfg 416x416 62.8% 41.2% 55®96(V) 245M yolov4.conv.137
yolov4.cfg 320x320 60% 38% 63®123(V) 245M yolov4.conv.137
yolov4-tiny.cfg 416x416 40% -% 330®371(1080Ti) 23.1M yolov4-tiny.conv.29
yolov3.cfg 414x416 55.3% -% 66® 236M darknet53.conv.74
yolov3-tiny.cfg 416x416 33.1% -% 370® 33.7M yolov3-tiny.conv.11
enet-coco.cfg(yolov3 efficientnetb0) None 45.5% -% 55® 18.3M enetb0-coco.conv.74

对于上述众多模型,会选择其中部分进行训练并获得训练好的模型,所有工作将在两台有8个V100的机器上进行

所有配置中的6,7行来控制显存的使用

2.3.1 新建cfg/yolov4_vechle.cfg

可以复制darnet下cfg/yolov4-custom.cfg,再根据自己情况进行修改,一次修改,以后基本不会变:

  • 第8,9行:width,height 可以设置为416,608,832等其它32的倍数,这里设置608
  • 第20行:max_batches 可以设置为分类数乘2000,但不少于图片数,所以建议设大一点,图片数乘5,第张图可以见到5次
  • 第22行:steps分别是max_batches的0.8和0.9
  • 第744行:stopbackward的数值表示迭代这么多次后,前边的层将停止更新,可以注释掉,用来做迁移学习
  • 第970,1058,1146行:修改classes为我们的具体分类数
  • 第963,1051,1139行:修改filters为(classes+5)*3

2.3.2 新建cfg/yolov4_tiny_vechle.cfg

可以复制darnet下cfg/yolov4-tiny-custom.cfg,再根据自己情况进行修改,一次修改,以后基本不会变:

  • 第8,9行:width,height 可以设置为416,608,832等其它32的倍数,这里设置608
  • 第20行:max_batches 可以设置为分类数乘2000,但不少于图片数,所以建议设大一点,图片数乘5,第张图可以见到5次
  • 第22行:steps分别是max_batches的0.8和0.9
  • 第220,269行:修改classes为我们的具体分类数
  • 第212,263行:修改filters为(classes+5)*3

2.3.3 新建cfg/yolo3_vechcle.cfg

可以复制darnet下cfg/yolov3-voc.cfg,再根据自己情况进行修改,一次修改,以后基本不会变:

  • 第8,9行:width,height 可以设置为416,608,832等其它32的倍数,这里设置608
  • 第20行:max_batches 可以设置为分类数乘2000,但不少于图片数,所以建议设大一点,图片数乘5,第张图可以见到5次
  • 第22行:steps分别是max_batches的0.8和0.9
  • 第611,695,779行:修改classes为我们的具体分类数
  • 第605,689,773行:修改filters为(classes+5)*3

2.3.4 新建cfg/yolo3_vechcle_mosaic.cfg

可以复制darnet下cfg/yolov3-voc.cfg,再根据自己情况进行修改,一次修改,以后基本不会变:

  • 第8,9行:width,height 可以设置为416,608,832等其它32的倍数,这里设置608
  • 第20行:max_batches 可以设置为分类数乘2000,但不少于图片数,所以建议设大一点,图片数乘5,第张图可以见到5次
  • 第22行:steps分别是max_batches的0.8和0.9
  • 第25行:加mosaic=1
  • 第612,696,780行:修改classes为我们的具体分类数
  • 第606,690,774行:修改filters为(classes+5)*3

2.3.5 新建cfg/yolo3_tiny_vechcle.cfg

可以复制darnet下cfg/yolov3-tiny.cfg,再根据自己情况进行修改,一次修改,以后基本不会变:

  • 第8,9行:width,height 可以设置为416,608,832等其它32的倍数,这里设置608
  • 第20行:max_batches 可以设置为分类数乘2000,但不少于图片数,所以建议设大一点,图片数乘5,第张图可以见到5次
  • 第22行:steps分别是max_batches的0.8和0.9
  • 第135,177行:修改classes为我们的具体分类数
  • 第127,171行:修改filters为(classes+5)*3

2.3.6 新建cfg/enetb0_vechcle.cfg

模型大小于yolov4 的十分之一,精度与416x416相当,速度也相当,所以用efficient b0做backbone

可以复制darnet下cfg/enet-coco.cfg,再根据自己情况进行修改,一次修改,以后基本不会变:

  • 第8,9行:width,height 可以设置为416,608,832等其它32的倍数
  • 第20行:max_batches 可以设置为分类数乘2000,但不少于图片数,所以建议设大一点,图片数乘5,第张图可以见到5次
  • 第22行:steps分别是max_batches的0.8和0.9
  • 第1015,1066行:修改classes为我们的具体分类数
  • 第1007,1060行:修改filters为(classes+5)*3

2.3.7 新建cfg/yolov4_p6_vechcle.cfg

可以复制darnet下cfg/yolov4_p6.cfg,再根据自己情况进行修改,一次修改,以后基本不会变:

  • 第8,9行:width,height 可以设置为1280
  • 第20行:max_batches 可以设置为分类数乘2000,但不少于图片数,所以建议设大一点,图片数乘5,第张图可以见到5次
  • 第22行:steps分别是max_batches的0.8和0.9
  • 第2144,2189,2234,2279行:修改classes为我们的具体分类数
  • 第2136,2189,2226,2271行:修改filters为(classes+5)*4

2.3.8 新建cfg/yolov4_p5_vechcle.cfg

可以复制darnet下cfg/yolov4_p5.cfg,再根据自己情况进行修改,一次修改,以后基本不会变:

  • 第8,9行:width,height 可以设置为896
  • 第20行:max_batches 可以设置为分类数乘2000,但不少于图片数,所以建议设大一点,图片数乘5,第张图可以见到5次
  • 第22行:steps分别是max_batches的0.8和0.9
  • 第1728,1773,1818行:修改classes为我们的具体分类数
  • 第1720,1765,1810行:修改filters为(classes+5)*4

2.3.9 新建cfg/yolov4_csp_x_swish_vechcle.cfg

可以复制darnet下cfg/yolov4-csp-x-swish.cfg,再根据自己情况进行修改,一次修改,以后基本不会变:

  • 第8,9行:width,height 可以设置为640
  • 第20行:max_batches 可以设置为分类数乘2000,但不少于图片数,所以建议设大一点,图片数乘5,第张图可以见到5次
  • 第22行:steps分别是max_batches的0.8和0.9
  • 第1453,1496,1539行:修改classes为我们的具体分类数
  • 第1447,1490,1533行:修改filters为(classes+5)*3

2.3.10 新建cfg/yolov4_csp_swish_vechcle.cfg

可以复制darnet下cfg/yolov4-csp-swish.cfg,再根据自己情况进行修改,一次修改,以后基本不会变:

  • 第8,9行:width,height 可以设置为640
  • 第20行:max_batches 可以设置为分类数乘2000,但不少于图片数,所以建议设大一点,图片数乘5,第张图可以见到5次
  • 第22行:steps分别是max_batches的0.8和0.9
  • 第1252,1295,1338行:修改classes为我们的具体分类数
  • 第1446,1489,1332行:修改filters为(classes+5)*3

2.3.11 新建cfg/yolov4x_mish_vechcle.cfg

可以复制darnet下cfg/yolov4x-mish.cfg,再根据自己情况进行修改,一次修改,以后基本不会变:

  • 第8,9行:width,height 可以设置为640
  • 第20行:max_batches 可以设置为分类数乘2000,但不少于图片数,所以建议设大一点,图片数乘5,第张图可以见到5次
  • 第22行:steps分别是max_batches的0.8和0.9
  • 第1159,1289,1419行:修改classes为我们的具体分类数
  • 第1152,1282,1412行:修改filters为(classes+5)*3

2.3.12 新建cfg/yolov4_csp_vechcle.cfg

可以复制darnet下cfg/yolov4-csp.cfg,再根据自己情况进行修改,一次修改,以后基本不会变:

  • 第8,9行:width,height 可以设置为640
  • 第20行:max_batches 可以设置为分类数乘2000,但不少于图片数,所以建议设大一点,图片数乘5,第张图可以见到5次
  • 第22行:steps分别是max_batches的0.8和0.9
  • 第1034,1148,1262行:修改classes为我们的具体分类数
  • 第1027,1141,1255行:修改filters为(classes+5)*3

3.训练自己的数据集

3.1 下载预训练权重

  • yolov4 已下载好yolov4.conv.137,放到cfg目录下
  • yolov4-tiny 已下载好yolov4-tiny.conv.29,放到cfg目录下
  • yolov3 已下载好darknet53.conv.74,放到cfg目录下
  • yolov3-tiny 已下载好yolov3-tiny.conv.11,放到cfg目录下

其它预训练权重也下载好了,参见2.3节中那个表中预训练模型的名称这里就不再一一列举了

3.2 开始模型的训练

训练的命令有,以下是多GPU训练:


CUDA_VISIBLE_DEVICES=0,1,2,3 nohup darknet detector train cfg/vechle.data cfg/vechle.cfg cfg/yolov4.conv.137 -gpus 0,1,2,3 -dont_show -map 2>&1 >logs/train20210713.log &

3.2.1 Yolo V4训练

with open('train_yolov4.sh','w') as f:
    f.write("nohup darknet detector train cfg/vechcle.data cfg/yolov4_vechcle.cfg cfg/yolov4.conv.137 -gpus 6,7 -dont_show -map 2>&1 >logs/yolov4.log &")
with open('train_yolov4.sh') as f:
    print(f.read())
nohup darknet detector train cfg/vechcle.data cfg/yolov4_vechcle.cfg cfg/yolov4.conv.137 -gpus 6,7 -dont_show -map 2>&1 >logs/yolov4.log &
#建议在shell 中执行该命令
import os 
os.system("sh train_yolov4.sh")
0

3.2.2 Yolo V4 tiny训练

with open('train_yolov4_tiny.sh','w') as f:
    f.write("nohup darknet detector train cfg/vechcle.data cfg/yolov4_tiny_vechcle.cfg cfg/yolov4-tiny.conv.29 -gpus 5 -dont_show -map 2>&1 >logs/yolov4_tiny.log &")
with open('train_yolov4_tiny.sh') as f:
    print(f.read())
nohup darknet detector train cfg/vechcle.data cfg/yolov4_tiny_vechcle.cfg cfg/yolov4-tiny.conv.29 -gpus 5 -dont_show -map 2>&1 >logs/yolov4_tiny.log &
#建议在shell 中执行该命令
import os 
os.system("sh train_yolov4_tiny.sh")

3.2.3 Yolo V3 训练

with open('train_yolov3.sh','w') as f:
    f.write("nohup darknet detector train cfg/vechcle.data cfg/yolov3_vechcle.cfg cfg/darknet53.conv.74 -gpus 3,4 -dont_show -map 2>&1 >logs/yolov3.log &")
with open('train_yolov3.sh') as f:
    print(f.read())
nohup darknet detector train cfg/vechcle.data cfg/yolov3_vechcle.cfg cfg/darknet53.conv.74 -gpus 3,4 -dont_show -map 2>&1 >logs/yolov3.log &

3.2.4 Yolov3 加mosaic数据增强训练

with open('train_yolov3_mosaic.sh','w') as f:
    f.write("nohup darknet detector train cfg/vechcle.data cfg/yolov3_vechcle_mosaic.cfg cfg/darknet53.conv.74 -gpus 2,5 -dont_show -map 2>&1 >logs/yolov3_mosaic.log &")
with open('train_yolov3_mosaic.sh') as f:
    print(f.read())
nohup darknet detector train cfg/vechcle.data cfg/yolov3_vechcle_mosaic.cfg cfg/darknet53.conv.74 -gpus 2,5 -dont_show -map 2>&1 >logs/yolov3_mosaic.log &

3.2.5 Yolo V3 tiny训练

with open('train_yolov3_tiny.sh','w') as f:
    f.write("nohup darknet detector train cfg/vechcle.data cfg/yolov3_tiny_vechcle.cfg cfg/yolov3-tiny.conv.11 -gpus 2 -dont_show -map 2>&1 >logs/yolov3_tiny.log &")
with open('train_yolov3_tiny.sh') as f:
    print(f.read())
nohup darknet detector train cfg/vechcle.data cfg/yolov3_tiny_vechcle.cfg cfg/yolov3-tiny.conv.11 -gpus 2 -dont_show -map 2>&1 >logs/yolov3_tiny.log &

3.2.6 Yolo V3 efficientb0训练

with open('train_yolov3_enet.sh','w') as f:
    f.write("nohup darknet detector train cfg/vechcle.data cfg/enetb0_vechcle.cfg cfg/enetb0-coco.conv.132 -gpus 1 -dont_show -map 2>&1 >logs/yolov3_enet.log &")
with open('train_yolov3_enet.sh') as f:
    print(f.read())
nohup darknet detector train cfg/vechcle.data cfg/enetb0_vechcle.cfg cfg/enetb0-coco.conv.132 -gpus 1 -dont_show -map 2>&1 >logs/yolov3_enet.log &

3.2.7 Yolo V4 p6训练

with open('train_yolov4_p6.sh','w') as f:
    f.write("nohup darknet detector train cfg/vechcle.data cfg/yolov4_p6_vechcle.cfg cfg/yolov4-p6.conv.289 -gpus 6,7 -dont_show -map 2>&1 >logs/yolov4_p6.log &")
with open('train_yolov4_p6.sh') as f:
    print(f.read())
nohup darknet detector train cfg/vechcle.data cfg/yolov4_p6_vechcle.cfg cfg/yolov4-p6.conv.289 -gpus 6,7 -dont_show -map 2>&1 >logs/yolov4_p6.log &

3.2.8 Yolo V4 p5训练

with open('train_yolov4_p5.sh','w') as f:
    f.write("nohup darknet detector train cfg/vechcle.data cfg/yolov4_p5_vechcle.cfg cfg/yolov4-p5.conv.232 -gpus 3,4 -dont_show -map 2>&1 >logs/yolov4_p5.log &")
with open('train_yolov4_p5.sh') as f:
    print(f.read())
nohup darknet detector train cfg/vechcle.data cfg/yolov4_p5_vechcle.cfg cfg/yolov4-p5.conv.232 -gpus 3,4 -dont_show -map 2>&1 >logs/yolov4_p5.log &

3.2.9 Yolo V4 csp x swish训练

with open('train_yolov4_csp_x_swish.sh','w') as f:
    f.write("nohup darknet detector train cfg/vechcle.data cfg/yolov4_csp_x_swish_vechcle.cfg cfg/yolov4-csp-x-swish.conv.192 -gpus 0,1 -dont_show -map 2>&1 >logs/yolov4_csp_x_swish.log &")
with open('train_yolov4_csp_x_swish.sh') as f:
    print(f.read())
nohup darknet detector train cfg/vechcle.data cfg/yolov4_csp_x_swish_vechcle.cfg cfg/yolov4-csp-x-swish.conv.192 -gpus 0,1 -dont_show -map 2>&1 >logs/yolov4_csp_x_swish.log &

3.2.10 Yolo V4 csp swish训练

with open('train_yolov4_csp_swish.sh','w') as f:
    f.write("nohup darknet detector train cfg/vechcle.data cfg/yolov4_csp_swish_vechcle.cfg cfg/yolov4-csp-swish.conv.164 -gpus 0,1 -dont_show -map 2>&1 >logs/yolov4_csp_swish.log &")
with open('train_yolov4_csp_swish.sh') as f:
    print(f.read())
nohup darknet detector train cfg/vechcle.data cfg/yolov4_csp_swish_vechcle.cfg cfg/yolov4-csp-swish.conv.164 -gpus 0,1 -dont_show -map 2>&1 >logs/yolov4_csp_swish.log &

3.2.11 Yolo V4 x mish训练

with open('train_yolov4x_mish.sh','w') as f:
    f.write("nohup darknet detector train cfg/vechcle.data cfg/yolov4x_mish_vechcle.cfg cfg/yolov4x-mish.conv.166 -gpus 2,3 -dont_show -map 2>&1 >logs/yolov4x_mish.log &")
with open('train_yolov4x_mish.sh') as f:
    print(f.read())
nohup darknet detector train cfg/vechcle.data cfg/yolov4x_mish_vechcle.cfg cfg/yolov4x-mish.conv.166 -gpus 2,3 -dont_show -map 2>&1 >logs/yolov4x_mish.log &

3.2.12 Yolo V4 csp 训练

with open('train_yolov4_csp.sh','w') as f:
    f.write("nohup darknet detector train cfg/vechcle.data cfg/yolov4_csp_vechcle.cfg cfg/yolov4-csp.conv.142 -gpus 6,7 -dont_show -map 2>&1 >logs/yolov4_csp.log &")
with open('train_yolov4x_mish.sh') as f:
    print(f.read())
nohup darknet detector train cfg/vechcle.data cfg/yolov4x_mish_vechcle.cfg cfg/yolov4x-mish.conv.166 -gpus 2,3 -dont_show -map 2>&1 >logs/yolov4x_mish.log &

4、模型的推理

在模型使用时,修改配置文件batch=1 subdivisions=1用于推理。别外,可以能过修改.cfg文件中的height,width来修改模型输入。可以是608608,832832或其它什么可32的倍数。改大输入会对小目标有提升。这时模型无须再次训练,还用原来模型即可。当然要从概本上提升精度,还是要用大输入尺寸来训练模型。

4.1 命令行对图片和视频模型的推理

%ºsh
darknet detector test cfg/vechle.data cfg/vechle.cfg backup/vechle_best.weights /workspace/vechcle/VOCdevkit/VOC2007_DEST/JPEGImages/000004.jpg -thresh 0.25
net.optimized_memory = 0 
mini_batch = 1, batch = 16, time_steps = 1, train = 0 
Create CUDA-stream - 0 
 Create cudnn-handle 0 
nms_kind: greedynms (1), beta = 0.600000 
nms_kind: greedynms (1), beta = 0.600000 
nms_kind: greedynms (1), beta = 0.600000 

 seen 64, trained: 918 K-images (14 Kilo-batches_64) 
 Detection layer: 139 - type = 28 
 Detection layer: 150 - type = 28 
 Detection layer: 161 - type = 28 
/workspace/vechcle/VOCdevkit/VOC2007_DEST/JPEGImages/000004.jpg: Predicted in 19.198000 milli-seconds.
car: 89%
car: 77%
truck: 49%
truck: 28%
car: 33%
car: 97%
car: 98%
car: 96%
car: 98%
car: 99%
car: 99%


 CUDA-version: 10010 (11020), cuDNN: 7.6.5, GPU count: 8  
 OpenCV version: 4.5.0
 0 : compute_capability = 700, cudnn_half = 0, GPU: Tesla V100-SXM2-32GB 
   layer   filters  size/strd(dil)      input                output
   0 conv     32       3 x 3/ 1    608 x 608 x   3 ->  608 x 608 x  32 0.639 BF
   1 conv     64       3 x 3/ 2    608 x 608 x  32 ->  304 x 304 x  64 3.407 BF
   2 conv     64       1 x 1/ 1    304 x 304 x  64 ->  304 x 304 x  64 0.757 BF
   3 route  1 		                           ->  304 x 304 x  64 
   4 conv     64       1 x 1/ 1    304 x 304 x  64 ->  304 x 304 x  64 0.757 BF
   5 conv     32       1 x 1/ 1    304 x 304 x  64 ->  304 x 304 x  32 0.379 BF
   6 conv     64       3 x 3/ 1    304 x 304 x  32 ->  304 x 304 x  64 3.407 BF
   7 Shortcut Layer: 4,  wt = 0, wn = 0, outputs: 304 x 304 x  64 0.006 BF
   8 conv     64       1 x 1/ 1    304 x 304 x  64 ->  304 x 304 x  64 0.757 BF
   9 route  8 2 	                           ->  304 x 304 x 128 
  10 conv     64       1 x 1/ 1    304 x 304 x 128 ->  304 x 304 x  64 1.514 BF
  11 conv    128       3 x 3/ 2    304 x 304 x  64 ->  152 x 152 x 128 3.407 BF
  12 conv     64       1 x 1/ 1    152 x 152 x 128 ->  152 x 152 x  64 0.379 BF
  13 route  11 		                           ->  152 x 152 x 128 
  14 conv     64       1 x 1/ 1    152 x 152 x 128 ->  152 x 152 x  64 0.379 BF
  15 conv     64       1 x 1/ 1    152 x 152 x  64 ->  152 x 152 x  64 0.189 BF
  16 conv     64       3 x 3/ 1    152 x 152 x  64 ->  152 x 152 x  64 1.703 BF
  17 Shortcut Layer: 14,  wt = 0, wn = 0, outputs: 152 x 152 x  64 0.001 BF
  18 conv     64       1 x 1/ 1    152 x 152 x  64 ->  152 x 152 x  64 0.189 BF
  19 conv     64       3 x 3/ 1    152 x 152 x  64 ->  152 x 152 x  64 1.703 BF
  20 Shortcut Layer: 17,  wt = 0, wn = 0, outputs: 152 x 152 x  64 0.001 BF
  21 conv     64       1 x 1/ 1    152 x 152 x  64 ->  152 x 152 x  64 0.189 BF
  22 route  21 12 	                           ->  152 x 152 x 128 
  23 conv    128       1 x 1/ 1    152 x 152 x 128 ->  152 x 152 x 128 0.757 BF
  24 conv    256       3 x 3/ 2    152 x 152 x 128 ->   76 x  76 x 256 3.407 BF
  25 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
  26 route  24 		                           ->   76 x  76 x 256 
  27 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
  28 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  29 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  30 Shortcut Layer: 27,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  31 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  32 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  33 Shortcut Layer: 30,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  34 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  35 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  36 Shortcut Layer: 33,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  37 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  38 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  39 Shortcut Layer: 36,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  40 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  41 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  42 Shortcut Layer: 39,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  43 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  44 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  45 Shortcut Layer: 42,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  46 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  47 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  48 Shortcut Layer: 45,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  49 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  50 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  51 Shortcut Layer: 48,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  52 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  53 route  52 25 	                           ->   76 x  76 x 256 
  54 conv    256       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 256 0.757 BF
  55 conv    512       3 x 3/ 2     76 x  76 x 256 ->   38 x  38 x 512 3.407 BF
  56 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
  57 route  55 		                           ->   38 x  38 x 512 
  58 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
  59 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  60 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  61 Shortcut Layer: 58,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  62 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  63 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  64 Shortcut Layer: 61,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  65 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  66 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  67 Shortcut Layer: 64,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  68 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  69 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  70 Shortcut Layer: 67,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  71 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  72 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  73 Shortcut Layer: 70,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  74 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  75 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  76 Shortcut Layer: 73,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  77 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  78 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  79 Shortcut Layer: 76,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  80 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  81 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  82 Shortcut Layer: 79,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  83 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  84 route  83 56 	                           ->   38 x  38 x 512 
  85 conv    512       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 512 0.757 BF
  86 conv   1024       3 x 3/ 2     38 x  38 x 512 ->   19 x  19 x1024 3.407 BF
  87 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
  88 route  86 		                           ->   19 x  19 x1024 
  89 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
  90 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
  91 conv    512       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x 512 1.703 BF
  92 Shortcut Layer: 89,  wt = 0, wn = 0, outputs:  19 x  19 x 512 0.000 BF
  93 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
  94 conv    512       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x 512 1.703 BF
  95 Shortcut Layer: 92,  wt = 0, wn = 0, outputs:  19 x  19 x 512 0.000 BF
  96 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
  97 conv    512       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x 512 1.703 BF
  98 Shortcut Layer: 95,  wt = 0, wn = 0, outputs:  19 x  19 x 512 0.000 BF
  99 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
 100 conv    512       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x 512 1.703 BF
 101 Shortcut Layer: 98,  wt = 0, wn = 0, outputs:  19 x  19 x 512 0.000 BF
 102 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
 103 route  102 87 	                           ->   19 x  19 x1024 
 104 conv   1024       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x1024 0.757 BF
 105 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 106 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 107 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 108 max                5x 5/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.005 BF
 109 route  107 		                           ->   19 x  19 x 512 
 110 max                9x 9/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.015 BF
 111 route  107 		                           ->   19 x  19 x 512 
 112 max               13x13/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.031 BF
 113 route  112 110 108 107 	                   ->   19 x  19 x2048 
 114 conv    512       1 x 1/ 1     19 x  19 x2048 ->   19 x  19 x 512 0.757 BF
 115 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 116 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 117 conv    256       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 256 0.095 BF
 118 upsample                 2x    19 x  19 x 256 ->   38 x  38 x 256
 119 route  85 		                           ->   38 x  38 x 512 
 120 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 121 route  120 118 	                           ->   38 x  38 x 512 
 122 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 123 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 124 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 125 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 126 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 127 conv    128       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 128 0.095 BF
 128 upsample                 2x    38 x  38 x 128 ->   76 x  76 x 128
 129 route  54 		                           ->   76 x  76 x 256 
 130 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
 131 route  130 128 	                           ->   76 x  76 x 256 
 132 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
 133 conv    256       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 256 3.407 BF
 134 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
 135 conv    256       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 256 3.407 BF
 136 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
 137 conv    256       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 256 3.407 BF
 138 conv     30       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x  30 0.089 BF
 139 yolo
[yolo] params: iou loss: ciou (4), iou_norm: 0.07, obj_norm: 1.00, cls_norm: 1.00, delta_norm: 1.00, scale_x_y: 1.20
 140 route  136 		                           ->   76 x  76 x 128 
 141 conv    256       3 x 3/ 2     76 x  76 x 128 ->   38 x  38 x 256 0.852 BF
 142 route  141 126 	                           ->   38 x  38 x 512 
 143 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 144 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 145 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 146 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 147 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 148 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 149 conv     30       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x  30 0.044 BF
 150 yolo
[yolo] params: iou loss: ciou (4), iou_norm: 0.07, obj_norm: 1.00, cls_norm: 1.00, delta_norm: 1.00, scale_x_y: 1.10
 151 route  147 		                           ->   38 x  38 x 256 
 152 conv    512       3 x 3/ 2     38 x  38 x 256 ->   19 x  19 x 512 0.852 BF
 153 route  152 116 	                           ->   19 x  19 x1024 
 154 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 155 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 156 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 157 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 158 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 159 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 160 conv     30       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x  30 0.022 BF
 161 yolo
[yolo] params: iou loss: ciou (4), iou_norm: 0.07, obj_norm: 1.00, cls_norm: 1.00, delta_norm: 1.00, scale_x_y: 1.05
Total BFLOPS 127.294 
avg_outputs = 1047336 
 Allocate additional workspace_size = 52.43 MB 
Loading weights from backup/vechle_best.weights...Done! Loaded 162 layers from weights-file 
Unable to init server: Could not connect: 拒绝连接
OpenCV exception: show_image_cv 

执行本代码后本身是会显示结果图的,但是由于本工作在docker中完成,并没有实现显示,结果保存在predictions.jpg

%ºsh
#指定GPU 6
darknet detector test cfg/vechle.data cfg/vechle.cfg backup/vechle_best.weights -i 6 /workspace/vechcle/VOCdevkit/VOC2007_DEST/JPEGImages/000004.jpg -thresh 0.25
net.optimized_memory = 0 
mini_batch = 1, batch = 16, time_steps = 1, train = 0 
Create CUDA-stream - 6 
 Create cudnn-handle 6 
nms_kind: greedynms (1), beta = 0.600000 
nms_kind: greedynms (1), beta = 0.600000 
nms_kind: greedynms (1), beta = 0.600000 

 seen 64, trained: 918 K-images (14 Kilo-batches_64) 
 Detection layer: 139 - type = 28 
 Detection layer: 150 - type = 28 
 Detection layer: 161 - type = 28 
/workspace/vechcle/VOCdevkit/VOC2007_DEST/JPEGImages/000004.jpg: Predicted in 19.047000 milli-seconds.
car: 89%
car: 77%
truck: 49%
truck: 28%
car: 33%
car: 97%
car: 98%
car: 96%
car: 98%
car: 99%
car: 99%


 CUDA-version: 10010 (11020), cuDNN: 7.6.5, GPU count: 8  
 OpenCV version: 4.5.0
 6 : compute_capability = 700, cudnn_half = 0, GPU: Tesla V100-SXM2-32GB 
   layer   filters  size/strd(dil)      input                output
   0 conv     32       3 x 3/ 1    608 x 608 x   3 ->  608 x 608 x  32 0.639 BF
   1 conv     64       3 x 3/ 2    608 x 608 x  32 ->  304 x 304 x  64 3.407 BF
   2 conv     64       1 x 1/ 1    304 x 304 x  64 ->  304 x 304 x  64 0.757 BF
   3 route  1 		                           ->  304 x 304 x  64 
   4 conv     64       1 x 1/ 1    304 x 304 x  64 ->  304 x 304 x  64 0.757 BF
   5 conv     32       1 x 1/ 1    304 x 304 x  64 ->  304 x 304 x  32 0.379 BF
   6 conv     64       3 x 3/ 1    304 x 304 x  32 ->  304 x 304 x  64 3.407 BF
   7 Shortcut Layer: 4,  wt = 0, wn = 0, outputs: 304 x 304 x  64 0.006 BF
   8 conv     64       1 x 1/ 1    304 x 304 x  64 ->  304 x 304 x  64 0.757 BF
   9 route  8 2 	                           ->  304 x 304 x 128 
  10 conv     64       1 x 1/ 1    304 x 304 x 128 ->  304 x 304 x  64 1.514 BF
  11 conv    128       3 x 3/ 2    304 x 304 x  64 ->  152 x 152 x 128 3.407 BF
  12 conv     64       1 x 1/ 1    152 x 152 x 128 ->  152 x 152 x  64 0.379 BF
  13 route  11 		                           ->  152 x 152 x 128 
  14 conv     64       1 x 1/ 1    152 x 152 x 128 ->  152 x 152 x  64 0.379 BF
  15 conv     64       1 x 1/ 1    152 x 152 x  64 ->  152 x 152 x  64 0.189 BF
  16 conv     64       3 x 3/ 1    152 x 152 x  64 ->  152 x 152 x  64 1.703 BF
  17 Shortcut Layer: 14,  wt = 0, wn = 0, outputs: 152 x 152 x  64 0.001 BF
  18 conv     64       1 x 1/ 1    152 x 152 x  64 ->  152 x 152 x  64 0.189 BF
  19 conv     64       3 x 3/ 1    152 x 152 x  64 ->  152 x 152 x  64 1.703 BF
  20 Shortcut Layer: 17,  wt = 0, wn = 0, outputs: 152 x 152 x  64 0.001 BF
  21 conv     64       1 x 1/ 1    152 x 152 x  64 ->  152 x 152 x  64 0.189 BF
  22 route  21 12 	                           ->  152 x 152 x 128 
  23 conv    128       1 x 1/ 1    152 x 152 x 128 ->  152 x 152 x 128 0.757 BF
  24 conv    256       3 x 3/ 2    152 x 152 x 128 ->   76 x  76 x 256 3.407 BF
  25 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
  26 route  24 		                           ->   76 x  76 x 256 
  27 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
  28 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  29 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  30 Shortcut Layer: 27,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  31 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  32 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  33 Shortcut Layer: 30,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  34 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  35 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  36 Shortcut Layer: 33,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  37 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  38 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  39 Shortcut Layer: 36,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  40 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  41 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  42 Shortcut Layer: 39,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  43 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  44 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  45 Shortcut Layer: 42,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  46 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  47 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  48 Shortcut Layer: 45,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  49 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  50 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  51 Shortcut Layer: 48,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  52 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  53 route  52 25 	                           ->   76 x  76 x 256 
  54 conv    256       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 256 0.757 BF
  55 conv    512       3 x 3/ 2     76 x  76 x 256 ->   38 x  38 x 512 3.407 BF
  56 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
  57 route  55 		                           ->   38 x  38 x 512 
  58 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
  59 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  60 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  61 Shortcut Layer: 58,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  62 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  63 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  64 Shortcut Layer: 61,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  65 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  66 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  67 Shortcut Layer: 64,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  68 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  69 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  70 Shortcut Layer: 67,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  71 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  72 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  73 Shortcut Layer: 70,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  74 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  75 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  76 Shortcut Layer: 73,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  77 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  78 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  79 Shortcut Layer: 76,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  80 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  81 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  82 Shortcut Layer: 79,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  83 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  84 route  83 56 	                           ->   38 x  38 x 512 
  85 conv    512       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 512 0.757 BF
  86 conv   1024       3 x 3/ 2     38 x  38 x 512 ->   19 x  19 x1024 3.407 BF
  87 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
  88 route  86 		                           ->   19 x  19 x1024 
  89 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
  90 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
  91 conv    512       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x 512 1.703 BF
  92 Shortcut Layer: 89,  wt = 0, wn = 0, outputs:  19 x  19 x 512 0.000 BF
  93 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
  94 conv    512       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x 512 1.703 BF
  95 Shortcut Layer: 92,  wt = 0, wn = 0, outputs:  19 x  19 x 512 0.000 BF
  96 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
  97 conv    512       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x 512 1.703 BF
  98 Shortcut Layer: 95,  wt = 0, wn = 0, outputs:  19 x  19 x 512 0.000 BF
  99 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
 100 conv    512       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x 512 1.703 BF
 101 Shortcut Layer: 98,  wt = 0, wn = 0, outputs:  19 x  19 x 512 0.000 BF
 102 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
 103 route  102 87 	                           ->   19 x  19 x1024 
 104 conv   1024       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x1024 0.757 BF
 105 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 106 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 107 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 108 max                5x 5/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.005 BF
 109 route  107 		                           ->   19 x  19 x 512 
 110 max                9x 9/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.015 BF
 111 route  107 		                           ->   19 x  19 x 512 
 112 max               13x13/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.031 BF
 113 route  112 110 108 107 	                   ->   19 x  19 x2048 
 114 conv    512       1 x 1/ 1     19 x  19 x2048 ->   19 x  19 x 512 0.757 BF
 115 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 116 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 117 conv    256       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 256 0.095 BF
 118 upsample                 2x    19 x  19 x 256 ->   38 x  38 x 256
 119 route  85 		                           ->   38 x  38 x 512 
 120 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 121 route  120 118 	                           ->   38 x  38 x 512 
 122 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 123 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 124 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 125 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 126 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 127 conv    128       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 128 0.095 BF
 128 upsample                 2x    38 x  38 x 128 ->   76 x  76 x 128
 129 route  54 		                           ->   76 x  76 x 256 
 130 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
 131 route  130 128 	                           ->   76 x  76 x 256 
 132 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
 133 conv    256       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 256 3.407 BF
 134 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
 135 conv    256       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 256 3.407 BF
 136 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
 137 conv    256       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 256 3.407 BF
 138 conv     30       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x  30 0.089 BF
 139 yolo
[yolo] params: iou loss: ciou (4), iou_norm: 0.07, obj_norm: 1.00, cls_norm: 1.00, delta_norm: 1.00, scale_x_y: 1.20
 140 route  136 		                           ->   76 x  76 x 128 
 141 conv    256       3 x 3/ 2     76 x  76 x 128 ->   38 x  38 x 256 0.852 BF
 142 route  141 126 	                           ->   38 x  38 x 512 
 143 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 144 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 145 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 146 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 147 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 148 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 149 conv     30       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x  30 0.044 BF
 150 yolo
[yolo] params: iou loss: ciou (4), iou_norm: 0.07, obj_norm: 1.00, cls_norm: 1.00, delta_norm: 1.00, scale_x_y: 1.10
 151 route  147 		                           ->   38 x  38 x 256 
 152 conv    512       3 x 3/ 2     38 x  38 x 256 ->   19 x  19 x 512 0.852 BF
 153 route  152 116 	                           ->   19 x  19 x1024 
 154 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 155 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 156 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 157 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 158 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 159 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 160 conv     30       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x  30 0.022 BF
 161 yolo
[yolo] params: iou loss: ciou (4), iou_norm: 0.07, obj_norm: 1.00, cls_norm: 1.00, delta_norm: 1.00, scale_x_y: 1.05
Total BFLOPS 127.294 
avg_outputs = 1047336 
 Allocate additional workspace_size = 52.43 MB 
Loading weights from backup/vechle_best.weights...Done! Loaded 162 layers from weights-file 
Unable to init server: Could not connect: 拒绝连接
OpenCV exception: show_image_cv 
%ºsh
#额外输出目标框的位置
darknet detector test cfg/vechle.data cfg/vechle.cfg backup/vechle_best.weights -ext_output /workspace/vechcle/VOCdevkit/VOC2007_DEST/JPEGImages/000004.jpg -thresh 0.25
net.optimized_memory = 0 
mini_batch = 1, batch = 16, time_steps = 1, train = 0 
Create CUDA-stream - 0 
 Create cudnn-handle 0 
nms_kind: greedynms (1), beta = 0.600000 
nms_kind: greedynms (1), beta = 0.600000 
nms_kind: greedynms (1), beta = 0.600000 

 seen 64, trained: 918 K-images (14 Kilo-batches_64) 
 Detection layer: 139 - type = 28 
 Detection layer: 150 - type = 28 
 Detection layer: 161 - type = 28 
/workspace/vechcle/VOCdevkit/VOC2007_DEST/JPEGImages/000004.jpg: Predicted in 19.375000 milli-seconds.
car: 89%	(left_x:   -0   top_y:  323   width:   17   height:   20)
car: 77%	(left_x:   12   top_y:  309   width:   75   height:   56)
truck: 49%	(left_x:   15   top_y:  310   width:   68   height:   53)
truck: 28%	(left_x:   54   top_y:  307   width:   29   height:   22)
car: 33%	(left_x:   78   top_y:  327   width:   13   height:   15)
car: 97%	(left_x:   85   top_y:  326   width:   29   height:   23)
car: 98%	(left_x:  108   top_y:  327   width:   35   height:   25)
car: 96%	(left_x:  137   top_y:  322   width:   50   height:   36)
car: 98%	(left_x:  173   top_y:  326   width:   78   height:   37)
car: 99%	(left_x:  229   top_y:  329   width:  103   height:   45)
car: 99%	(left_x:  362   top_y:  327   width:  134   height:   62)


 CUDA-version: 10010 (11020), cuDNN: 7.6.5, GPU count: 8  
 OpenCV version: 4.5.0
 0 : compute_capability = 700, cudnn_half = 0, GPU: Tesla V100-SXM2-32GB 
   layer   filters  size/strd(dil)      input                output
   0 conv     32       3 x 3/ 1    608 x 608 x   3 ->  608 x 608 x  32 0.639 BF
   1 conv     64       3 x 3/ 2    608 x 608 x  32 ->  304 x 304 x  64 3.407 BF
   2 conv     64       1 x 1/ 1    304 x 304 x  64 ->  304 x 304 x  64 0.757 BF
   3 route  1 		                           ->  304 x 304 x  64 
   4 conv     64       1 x 1/ 1    304 x 304 x  64 ->  304 x 304 x  64 0.757 BF
   5 conv     32       1 x 1/ 1    304 x 304 x  64 ->  304 x 304 x  32 0.379 BF
   6 conv     64       3 x 3/ 1    304 x 304 x  32 ->  304 x 304 x  64 3.407 BF
   7 Shortcut Layer: 4,  wt = 0, wn = 0, outputs: 304 x 304 x  64 0.006 BF
   8 conv     64       1 x 1/ 1    304 x 304 x  64 ->  304 x 304 x  64 0.757 BF
   9 route  8 2 	                           ->  304 x 304 x 128 
  10 conv     64       1 x 1/ 1    304 x 304 x 128 ->  304 x 304 x  64 1.514 BF
  11 conv    128       3 x 3/ 2    304 x 304 x  64 ->  152 x 152 x 128 3.407 BF
  12 conv     64       1 x 1/ 1    152 x 152 x 128 ->  152 x 152 x  64 0.379 BF
  13 route  11 		                           ->  152 x 152 x 128 
  14 conv     64       1 x 1/ 1    152 x 152 x 128 ->  152 x 152 x  64 0.379 BF
  15 conv     64       1 x 1/ 1    152 x 152 x  64 ->  152 x 152 x  64 0.189 BF
  16 conv     64       3 x 3/ 1    152 x 152 x  64 ->  152 x 152 x  64 1.703 BF
  17 Shortcut Layer: 14,  wt = 0, wn = 0, outputs: 152 x 152 x  64 0.001 BF
  18 conv     64       1 x 1/ 1    152 x 152 x  64 ->  152 x 152 x  64 0.189 BF
  19 conv     64       3 x 3/ 1    152 x 152 x  64 ->  152 x 152 x  64 1.703 BF
  20 Shortcut Layer: 17,  wt = 0, wn = 0, outputs: 152 x 152 x  64 0.001 BF
  21 conv     64       1 x 1/ 1    152 x 152 x  64 ->  152 x 152 x  64 0.189 BF
  22 route  21 12 	                           ->  152 x 152 x 128 
  23 conv    128       1 x 1/ 1    152 x 152 x 128 ->  152 x 152 x 128 0.757 BF
  24 conv    256       3 x 3/ 2    152 x 152 x 128 ->   76 x  76 x 256 3.407 BF
  25 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
  26 route  24 		                           ->   76 x  76 x 256 
  27 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
  28 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  29 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  30 Shortcut Layer: 27,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  31 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  32 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  33 Shortcut Layer: 30,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  34 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  35 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  36 Shortcut Layer: 33,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  37 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  38 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  39 Shortcut Layer: 36,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  40 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  41 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  42 Shortcut Layer: 39,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  43 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  44 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  45 Shortcut Layer: 42,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  46 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  47 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  48 Shortcut Layer: 45,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  49 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  50 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  51 Shortcut Layer: 48,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  52 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  53 route  52 25 	                           ->   76 x  76 x 256 
  54 conv    256       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 256 0.757 BF
  55 conv    512       3 x 3/ 2     76 x  76 x 256 ->   38 x  38 x 512 3.407 BF
  56 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
  57 route  55 		                           ->   38 x  38 x 512 
  58 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
  59 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  60 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  61 Shortcut Layer: 58,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  62 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  63 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  64 Shortcut Layer: 61,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  65 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  66 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  67 Shortcut Layer: 64,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  68 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  69 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  70 Shortcut Layer: 67,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  71 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  72 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  73 Shortcut Layer: 70,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  74 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  75 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  76 Shortcut Layer: 73,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  77 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  78 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  79 Shortcut Layer: 76,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  80 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  81 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  82 Shortcut Layer: 79,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  83 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  84 route  83 56 	                           ->   38 x  38 x 512 
  85 conv    512       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 512 0.757 BF
  86 conv   1024       3 x 3/ 2     38 x  38 x 512 ->   19 x  19 x1024 3.407 BF
  87 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
  88 route  86 		                           ->   19 x  19 x1024 
  89 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
  90 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
  91 conv    512       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x 512 1.703 BF
  92 Shortcut Layer: 89,  wt = 0, wn = 0, outputs:  19 x  19 x 512 0.000 BF
  93 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
  94 conv    512       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x 512 1.703 BF
  95 Shortcut Layer: 92,  wt = 0, wn = 0, outputs:  19 x  19 x 512 0.000 BF
  96 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
  97 conv    512       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x 512 1.703 BF
  98 Shortcut Layer: 95,  wt = 0, wn = 0, outputs:  19 x  19 x 512 0.000 BF
  99 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
 100 conv    512       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x 512 1.703 BF
 101 Shortcut Layer: 98,  wt = 0, wn = 0, outputs:  19 x  19 x 512 0.000 BF
 102 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
 103 route  102 87 	                           ->   19 x  19 x1024 
 104 conv   1024       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x1024 0.757 BF
 105 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 106 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 107 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 108 max                5x 5/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.005 BF
 109 route  107 		                           ->   19 x  19 x 512 
 110 max                9x 9/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.015 BF
 111 route  107 		                           ->   19 x  19 x 512 
 112 max               13x13/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.031 BF
 113 route  112 110 108 107 	                   ->   19 x  19 x2048 
 114 conv    512       1 x 1/ 1     19 x  19 x2048 ->   19 x  19 x 512 0.757 BF
 115 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 116 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 117 conv    256       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 256 0.095 BF
 118 upsample                 2x    19 x  19 x 256 ->   38 x  38 x 256
 119 route  85 		                           ->   38 x  38 x 512 
 120 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 121 route  120 118 	                           ->   38 x  38 x 512 
 122 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 123 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 124 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 125 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 126 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 127 conv    128       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 128 0.095 BF
 128 upsample                 2x    38 x  38 x 128 ->   76 x  76 x 128
 129 route  54 		                           ->   76 x  76 x 256 
 130 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
 131 route  130 128 	                           ->   76 x  76 x 256 
 132 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
 133 conv    256       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 256 3.407 BF
 134 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
 135 conv    256       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 256 3.407 BF
 136 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
 137 conv    256       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 256 3.407 BF
 138 conv     30       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x  30 0.089 BF
 139 yolo
[yolo] params: iou loss: ciou (4), iou_norm: 0.07, obj_norm: 1.00, cls_norm: 1.00, delta_norm: 1.00, scale_x_y: 1.20
 140 route  136 		                           ->   76 x  76 x 128 
 141 conv    256       3 x 3/ 2     76 x  76 x 128 ->   38 x  38 x 256 0.852 BF
 142 route  141 126 	                           ->   38 x  38 x 512 
 143 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 144 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 145 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 146 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 147 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 148 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 149 conv     30       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x  30 0.044 BF
 150 yolo
[yolo] params: iou loss: ciou (4), iou_norm: 0.07, obj_norm: 1.00, cls_norm: 1.00, delta_norm: 1.00, scale_x_y: 1.10
 151 route  147 		                           ->   38 x  38 x 256 
 152 conv    512       3 x 3/ 2     38 x  38 x 256 ->   19 x  19 x 512 0.852 BF
 153 route  152 116 	                           ->   19 x  19 x1024 
 154 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 155 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 156 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 157 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 158 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 159 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 160 conv     30       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x  30 0.022 BF
 161 yolo
[yolo] params: iou loss: ciou (4), iou_norm: 0.07, obj_norm: 1.00, cls_norm: 1.00, delta_norm: 1.00, scale_x_y: 1.05
Total BFLOPS 127.294 
avg_outputs = 1047336 
 Allocate additional workspace_size = 52.43 MB 
Loading weights from backup/vechle_best.weights...Done! Loaded 162 layers from weights-file 
Unable to init server: Could not connect: 拒绝连接
OpenCV exception: show_image_cv 
%ºsh
#对视频进行测试并保存结果
darknet detector demo cfg/vechle.data cfg/vechle.cfg backup/vechle_best.weights test.mp4 -out_filename result.avi
%ºsh
#对摄像头
darknet detector demo cfg/vechle.data cfg/vechle.cfg backup/vechle_best.weights -c 0 -out_filename result.avi
%ºsh
#处理多张图片
darknet detector demo cfg/vechle.data cfg/vechle.cfg backup/vechle_best.weights -dont_show -ext_output < cfg/val.txt > result.txt
Process is interrupted.
%ºsh
#生成伪标签,可以用来将模型结果做为人工较正前的伪标签b
这个工作暂时也不做了,不难,主要是应用darknet 进行图片推理,然后获得结果,最后利用coco转voc中找码转成xml即可
UsageError: Line magic function `%ºsh` not found.

4.2 python对图片和视频的推理

4.2.1 图片推理

import os
import cv2
import numpy as np
import random
import sys
import infer
#os.chdir(os.path.dirname(os.path.abspath(__file__)))
# sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import darknet
class DetectImage:
    def __init__(self, dataPath, configPath, weightPath, namesPath, gpu_id=0):
        '''
        :param metaPath:   ***.data 存储各种参数
        :param configPath: ***.cfg  网络结构文件
        :param weightPath: ***.weights yolo的权重
        :param namesPath:  ***.names中的names路径,这里是便于读取使用
        '''
        
        #进行参数检验
        if not os.path.exists(configPath):
            raise(ValueError("Invalid config path {}".format(os.path.abspath(configPath))))
        if not os.path.exists(weightPath):
            raise(ValueError("Invalid weight path {}".format(os.path.abspath(weightPath))))
        if not os.path.exists(dataPath):
            raise(ValueError("Invalid data file path {}".format(os.path.abspath(dataPath))))
        if not isinstance(gpu_id,int):
            raise(ValueError("Invalid gpu id {}".format(gpu_id)))
        # 设置gpu_id
        darknet.set_gpu(gpu_id)
        # 网络,各种参数,分类名称,分类对应的颜色,batch_size=1,单张图片进行处理
        self.network, self.class_names, self.class_colors = darknet.load_network(
        configPath,
        dataPath,
        weightPath,
        batch_size=1)
 
 
   
 
    def predict_image(self, image, thresh=0.25, is_show=False, save_path=''):
        '''
        :param image:    cv2.imread 图像, darknet自己会对图像进行预处理
        :param thresh:   置信度阈值, 其它阈值不变
        :param is_show:  是否将画框之后的图像返回
        :param save_path: 画框后的保存路径
        :return:         返回1个矩阵
        '''
        # bgr->rgb
        rgb_img = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
        # 获取图片大小,网络输入大小
        height, width = rgb_img.shape[:2]
        network_width = darknet.network_width(self.network)
        network_height = darknet.network_height(self.network)

        darknet_image = darknet.make_image(network_width, network_height, 3)
        image_resized = cv2.resize(rgb_img, (network_width, network_height),
                                   interpolation=cv2.INTER_LINEAR)
        darknet.copy_image_from_bytes(darknet_image, image_resized.tobytes())
        detections = darknet.detect_image(self.network, self.class_names, darknet_image, thresh=thresh)
        darknet.free_image(darknet_image)
#         image = darknet.draw_boxes(detections, image_resized, class_colors)
 
        
        origin_image_detections=[]
        for label, confidence, bbox in detections:
            x,y,w,h = bbox
            # 获取在原图中坐标
            x *= width / network_width
            w *= width / network_width
            y *= height / network_height
            h *= height / network_height
            left,top,right,bottom=darknet.bbox2points([x,y,w,h])
            origin_image_detections.append([label,confidence,[left,top,right,bottom]])
        if is_show:
            image = darknet.draw_boxes(origin_image_detections, rgb_img, self.class_colors)
            bgr_img = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
            # 保存图像
            if save_path:
                cv2.imwrite(save_path, bgr_img)
 
            return image  #返回画框的rgb图像
        return origin_image_detections
# if __name__=="__main__":

#     detect = DetectImage(dataPath=r'./cfg/vechcle.data',
#                configPath=r'./cfg/vechcle.cfg',
#                weightPath=r'./backup/vechcle_best.weights',
#                namesPath=r'./cfg/vechcle.names',
#                gpu_id=1)


#     detections = detect.predict_image(image)
#     darknet.print_detections(detections,True)
#     image = cv2.imread(r'./data/car.jpg', -1)
#     new_image=detect.predict_image(image, is_show=True,save_path='./data/pred.jpg')
# # detections = detect.predict_image(image)
# # darknet.print_detections(detections,True)

import os
import cv2
import numpy as np
import random
import sys
import infer
#os.chdir(os.path.dirname(os.path.abspath(__file__)))
# sys.path.append(os.path.dirname(os.path.abspath(__file__)))
import darknet
import threading

class DetectImage:
    _instance_lock = threading.Lock()
    def __init__(self, dataPath, configPath, weightPath, namesPath, gpu_id=0):
        '''
        :param metaPath:   ***.data 存储各种参数
        :param configPath: ***.cfg  网络结构文件
        :param weightPath: ***.weights yolo的权重
        :param namesPath:  ***.names中的names路径,这里是便于读取使用
        '''
        
        #进行参数检验
        if not os.path.exists(configPath):
            raise(ValueError("Invalid config path {}".format(os.path.abspath(configPath))))
        if not os.path.exists(weightPath):
            raise(ValueError("Invalid weight path {}".format(os.path.abspath(weightPath))))
        if not os.path.exists(dataPath):
            raise(ValueError("Invalid data file path {}".format(os.path.abspath(dataPath))))
        if not isinstance(gpu_id,int):
            raise(ValueError("Invalid gpu id {}".format(gpu_id)))
        # 设置gpu_id
        darknet.set_gpu(gpu_id)
        # 网络,各种参数,分类名称,分类对应的颜色,batch_size=1,单张图片进行处理
        self.network, self.class_names, self.class_colors = darknet.load_network(
        configPath,
        dataPath,
        weightPath,
        batch_size=1)
    def __new__(cls, *args, **kwargs):
        if not hasattr(cls, "__instance"):
            with DetectImage._instance_lock:
                if not hasattr(cls, "_instance"):
                    DetectImage._instance = super().__new__(cls)
        return DetectImage._instance
 
 
   
 
    def predict_image(self, image, thresh=0.25, is_show=False, save_path=''):
        '''
        :param image:    cv2.imread 图像, darknet自己会对图像进行预处理
        :param thresh:   置信度阈值, 其它阈值不变
        :param is_show:  是否将画框之后的图像返回
        :param save_path: 画框后的保存路径
        :return:         返回1个矩阵
        '''
        # bgr->rgb
        rgb_img = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
        # 获取图片大小,网络输入大小
        height, width = rgb_img.shape[:2]
        network_width = darknet.network_width(self.network)
        network_height = darknet.network_height(self.network)

        darknet_image = darknet.make_image(network_width, network_height, 3)
        image_resized = cv2.resize(rgb_img, (network_width, network_height),
                                   interpolation=cv2.INTER_LINEAR)
        darknet.copy_image_from_bytes(darknet_image, image_resized.tobytes())
        detections = darknet.detect_image(self.network, self.class_names, darknet_image, thresh=thresh)
        darknet.free_image(darknet_image)
#         image = darknet.draw_boxes(detections, image_resized, class_colors)
 
        
        origin_image_detections=[]
        for label, confidence, bbox in detections:
            x,y,w,h = bbox
            # 获取在原图中坐标
            x *= width / network_width
            w *= width / network_width
            y *= height / network_height
            h *= height / network_height
            left,top,right,bottom=darknet.bbox2points([x,y,w,h])
            origin_image_detections.append([label,confidence,[left,top,right,bottom]])
        if is_show:
            image = darknet.draw_boxes(origin_image_detections, rgb_img, self.class_colors)
            bgr_img = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
            # 保存图像
            if save_path:
                cv2.imwrite(save_path, bgr_img)
 
            return image  #返回画框的rgb图像
        return origin_image_detections

detect = DetectImage(dataPath=r'./cfg/vechcle.data',
               configPath=r'./cfg/vechcle.cfg',
               weightPath=r'./backup/vechcle_best.weights',
               namesPath=r'./cfg/vechcle.names',
               gpu_id=1)
image = cv2.imread(r'./data/car.jpg', -1)
new_image=detect.predict_image(image, is_show=True,save_path='./data/pred2.jpg')
# detections = detect.predict_image(image)
# darknet.print_detections(detections,True)


!pwd
/workspace/vechcle
import matplotlib.pyplot as plt
plt.figure(figsize=(30,15))
plt.imshow(new_image)
plt.show()

在这里插入图片描述

4.2.2 视频推理

import infer
import cv2
import darknet
import os
import time
import random

class DetectVideo:
    def __init__(self,args):
        self.args=args
        if not  isinstance(self.args,edict):
            print("""args is not a valid edict,please check:\n
            args.input type:str default=0\n
            args.out_filename type:str default= \n
            args.weights,default=yolov4.weights \n
            args.dont_show windown inference display. For headless systems \n
            args.ext_output display bbox coordinates of detected objects \n
            args.config_file "./cfg/yolov4.cfg path to config file \n
            args.data_file ./cfg/coco.data path to data file \n
            args.thresh 0.25 remove detections with confidence below this value\n
            args.gpu_id 1 int select use which gpu do inferece""")
            
        else:
            self.check_arguments_errors(self.args)
            # 设置gpu_id
            darknet.set_gpu(self.args.gpu_id)
            self.network, self.class_names, self.class_colors = darknet.load_network(
            self.args.config_file,
            self.args.data_file,
            self.args.weights,
            batch_size=1
             )
            self.width = darknet.network_width(self.network)
            self.height = darknet.network_height(self.network)
            input_path = self.str2int(self.args.input)
            self.cap = cv2.VideoCapture(input_path)
            
    def str2int(self,video_path):
        """
        argparse returns and string althout webcam uses int (0, 1 ...)
        Cast to int if needed
        """
        try:
            return int(video_path)
        except ValueError:
            return video_path
    def check_arguments_errors(self,args):
        assert 0 < args.thresh < 1, "Threshold should be a float between zero and one (non-inclusive)"
        if not os.path.exists(args.config_file):
            raise(ValueError("Invalid config path {}".format(os.path.abspath(args.config_file))))
        if not os.path.exists(args.weights):
            raise(ValueError("Invalid weight path {}".format(os.path.abspath(args.weights))))
        if not os.path.exists(args.data_file):
            raise(ValueError("Invalid data file path {}".format(os.path.abspath(args.data_file))))
        if self.str2int(args.input) == str and not os.path.exists(args.input):
            raise(ValueError("Invalid video path {}".format(os.path.abspath(args.input))))
    def set_saved_video(self,input_video, output_video, size):
        fourcc = cv2.VideoWriter_fourcc(*"mp4v")
        fps = int(input_video.get(cv2.CAP_PROP_FPS))
        video = cv2.VideoWriter(output_video, fourcc, fps, size)
        return video
    
    def video_capture(self):
        i=0
        while self.cap.isOpened():
            ret, frame = self.cap.read()
            if not ret:
                break
            frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
            height, width = frame_rgb.shape[:2]
            if i==0:
                video = self.set_saved_video(self.cap, self.args.out_filename, (width, height))
            i+=1
            frame_resized = cv2.resize(frame_rgb, (self.width, self.height),
                                       interpolation=cv2.INTER_LINEAR)

            img_for_detect = darknet.make_image(self.width, self.height, 3)
            darknet.copy_image_from_bytes(img_for_detect, frame_resized.tobytes())
            prev_time = time.time()
            detections = darknet.detect_image(self.network, self.class_names, img_for_detect, thresh=self.args.thresh)
            darknet.free_image(img_for_detect)
            fps = int(1/(time.time() - prev_time))
            print("FPS: {}".format(fps))
            origin_image_detections=[]
            for label, confidence, bbox in detections:
                x,y,w,h = bbox
                # 获取在原图中坐标
                x *= width / self.width
                w *= width / self.width
                y *= height / self.height
                h *= height / self.height
                left,top,right,bottom=darknet.bbox2points([x,y,w,h])
                origin_image_detections.append([label,confidence,[left,top,right,bottom]])
            image = darknet.draw_boxes(origin_image_detections, frame_rgb, self.class_colors)
            bgr_img = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
            if self.args.out_filename is not None:
                video.write(bgr_img)
            if not self.args.dont_show:
                cv2.imshow('Inference', bgr_img)
            if cv2.waitKey(fps) == 27:
                break
        self.cap.release()
        video.release()
        cv2.destroyAllWindows()
  
from easydict import EasyDict as edict
# from infer.detect_video import DetectVideo 

args=edict()
args.input='./data/road.mp4'
args.out_filename='./data/pred.mp4'
args.weights='./backup/vechcle_best.weights'
args.dont_show=True
args.ext_output=True
args.config_file='./cfg/vechcle.cfg'
args.data_file='./cfg/vechcle.data'
args.thresh=0.25
args.gpu_id=1
detectv = DetectVideo(args)


detectv.video_capture()
FPS: 48
FPS: 47
FPS: 50
FPS: 50
FPS: 49
FPS: 50
FPS: 50
FPS: 47
FPS: 50
FPS: 48
FPS: 47
FPS: 52
FPS: 52
FPS: 51
FPS: 51
FPS: 50
FPS: 50
FPS: 53
FPS: 52
FPS: 51
FPS: 51
FPS: 51
FPS: 50
FPS: 52
FPS: 52
FPS: 51
FPS: 51
FPS: 50
FPS: 50
FPS: 52
FPS: 50
FPS: 52
FPS: 52
FPS: 51
FPS: 50
FPS: 51
FPS: 56
FPS: 56

还有一种并行的方法,没有搞明白暂时,是这个样子
!python darknet_video.py ,以下代码为darknet_video.py中内容,但是在jupyter中没跑通

import random
import infer
import os
import cv2
import time
import darknet
import argparse
from threading import Thread, enumerate
from queue import Queue
from easydict import EasyDict as edict


def parser():
    parser = argparse.ArgumentParser(description="YOLO Object Detection")
    parser.add_argument("--input", type=str, default=0,
                        help="video source. If empty, uses webcam 0 stream")
    parser.add_argument("--out_filename", type=str, default="",
                        help="inference video name. Not saved if empty")
    parser.add_argument("--weights", default="yolov4.weights",
                        help="yolo weights path")
    parser.add_argument("--dont_show", action='store_true',
                        help="windown inference display. For headless systems")
    parser.add_argument("--ext_output", action='store_true',
                        help="display bbox coordinates of detected objects")
    parser.add_argument("--config_file", default="./cfg/yolov4.cfg",
                        help="path to config file")
    parser.add_argument("--data_file", default="./cfg/coco.data",
                        help="path to data file")
    parser.add_argument("--thresh", type=float, default=.25,
                        help="remove detections with confidence below this value")
    return parser.parse_args()


def str2int(video_path):
    """
    argparse returns and string althout webcam uses int (0, 1 ...)
    Cast to int if needed
    """
    try:
        return int(video_path)
    except ValueError:
        return video_path


def check_arguments_errors(args):
    assert 0 < args.thresh < 1, "Threshold should be a float between zero and one (non-inclusive)"
    if not os.path.exists(args.config_file):
        raise(ValueError("Invalid config path {}".format(os.path.abspath(args.config_file))))
    if not os.path.exists(args.weights):
        raise(ValueError("Invalid weight path {}".format(os.path.abspath(args.weights))))
    if not os.path.exists(args.data_file):
        raise(ValueError("Invalid data file path {}".format(os.path.abspath(args.data_file))))
    if str2int(args.input) == str and not os.path.exists(args.input):
        raise(ValueError("Invalid video path {}".format(os.path.abspath(args.input))))


def set_saved_video(input_video, output_video, size):

    fourcc = cv2.VideoWriter_fourcc(*"mp4v")
    fps = int(input_video.get(cv2.CAP_PROP_FPS))
#     print(f"fps{fps} size {size}")
    video = cv2.VideoWriter(output_video, fourcc, fps, size)
    return video


def video_capture(frame_queue, darknet_image_queue):
    while cap.isOpened():
        ret, frame = cap.read()
        if not ret:
            break
        frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
        frame_resized = cv2.resize(frame_rgb, (width, height),
                                   interpolation=cv2.INTER_LINEAR)
#         frame_queue.put(frame_resized)
        frame_queue.put(frame_rgb)
        img_for_detect = darknet.make_image(width, height, 3)
        darknet.copy_image_from_bytes(img_for_detect, frame_resized.tobytes())
        darknet_image_queue.put(img_for_detect)
    cap.release()


def inference(darknet_image_queue, detections_queue, fps_queue):
    while cap.isOpened():
        darknet_image = darknet_image_queue.get()
        prev_time = time.time()
        detections = darknet.detect_image(network, class_names, darknet_image, thresh=args.thresh)
        origin_image_detections=[]
        for label, confidence, bbox in detections:
            x,y,w,h = bbox
#             # 获取在原图中坐标
            x *= img_width / width
            w *= img_width / width
            y *= img_height / height
            h *= img_height / height
            left,top,right,bottom=darknet.bbox2points([x,y,w,h])
            origin_image_detections.append([label,confidence,[left,top,right,bottom]])
        detections_queue.put(origin_image_detections)
        fps = int(1/(time.time() - prev_time))
        fps_queue.put(fps)
        print("FPS: {}".format(fps))
#         darknet.print_detections(detections, args.ext_output)
        darknet.free_image(darknet_image)
    cap.release()


def drawing(frame_queue, detections_queue, fps_queue):
    random.seed(3)  # deterministic bbox colors
    video = set_saved_video(cap, args.out_filename, (int(img_width), int(img_height)))
    while cap.isOpened():
        frame_rgb = frame_queue.get()
        detections = detections_queue.get()
        
        fps = fps_queue.get()
        if frame_rgb is not None:
            image = darknet.draw_boxes(detections, frame_rgb, class_colors)
            image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
            if args.out_filename is not None:
#                 print("drawing ...,img.shape",image.shape)
                video.write(image)
            if not args.dont_show:
                cv2.imshow('Inference', image)
            if cv2.waitKey(fps) == 27:
                break
    cap.release()
    video.release()
    cv2.destroyAllWindows()


if __name__ == '__main__':

    frame_queue = Queue() #存放resized 后图片
    darknet_image_queue = Queue(maxsize=1)
    detections_queue = Queue(maxsize=1)
    fps_queue = Queue(maxsize=1)
    

#     args = parser()
    
    args=edict()
    args.input='./data/road.mp4'
    args.out_filename='./data/pred_thred.mp4'
    args.weights='./backup/vechcle_best.weights'
    args.dont_show=True
    args.ext_output=True
    args.config_file='./cfg/vechcle.cfg'
    args.data_file='./cfg/vechcle.data'
    args.thresh=0.25
    args.gpu_id=1
#     args = parser()
    check_arguments_errors(args)
    darknet.set_gpu(args.gpu_id)
    network, class_names, class_colors = darknet.load_network(
            args.config_file,
            args.data_file,
            args.weights,
            batch_size=1
        )
    
    width = darknet.network_width(network)
    height = darknet.network_height(network)
    input_path = str2int(args.input)
    cap = cv2.VideoCapture(input_path)
    img_width = cap.get(cv2.CAP_PROP_FRAME_WIDTH )
    img_height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
    
    Thread(target=video_capture, args=(frame_queue, darknet_image_queue)).start()
    Thread(target=inference, args=(darknet_image_queue, detections_queue, fps_queue)).start()
    Thread(target=drawing, args=(frame_queue, detections_queue, fps_queue)).start()

fps25 size (1280, 720)
frame_queue = Queue() #存放resized 后图片
darknet_image_queue = Queue(maxsize=1)
detections_queue = Queue(maxsize=1)
fps_queue = Queue(maxsize=1)


#     args = parser()

args=edict()
args.input='./data/road.mp4'
args.out_filename='./data/pred_thred.mp4'
args.weights='./backup/vechcle_best.weights'
args.dont_show=True
args.ext_output=True
args.config_file='./cfg/vechcle.cfg'
args.data_file='./cfg/vechcle.data'
args.thresh=0.25
args.gpu_id=1
#     args = parser()
check_arguments_errors(args)
darknet.set_gpu(args.gpu_id)
network, class_names, class_colors = darknet.load_network(
        args.config_file,
        args.data_file,
        args.weights,
        batch_size=1
    )

width = darknet.network_width(network)
height = darknet.network_height(network)
input_path = str2int(args.input)
cap = cv2.VideoCapture(input_path)
img_width = cap.get(cv2.CAP_PROP_FRAME_WIDTH )
img_height = cap.get(cv2.CAP_PROP_FRAME_HEIGHT)

Thread(target=video_capture, args=(frame_queue, darknet_image_queue)).start()
Thread(target=inference, args=(darknet_image_queue, detections_queue, fps_queue)).start()
Thread(target=drawing, args=(frame_queue, detections_queue, fps_queue)).start()

FPS: 11
FPS: 34
FPS: 26
FPS: 48
FPS: 37
FPS: 37
FPS: 47
FPS: 47
FPS: 45
FPS: 48
FPS: 50
FPS: 50
FPS: 46
FPS: 54
FPS: 55
FPS: 48
FPS: 51
FPS: 51
FPS: 55
FPS: 57
FPS: 56
FPS: 57
FPS: 54
FPS: 57
FPS: 54
FPS: 57
FPS: 57
FPS: 57
FPS: 53
FPS: 59
FPS: 55
FPS: 51
FPS: 47
FPS: 53
FPS: 55
FPS: 54
FPS: 54
fps25 size (1280, 720)
FPS: 52
FPS: 56
FPS: 57
FPS: 57
FPS: 54
FPS: 56
FPS: 56
FPS: 55
FPS: 54
FPS: 55
FPS: 57
FPS: 55
FPS: 55
FPS: 56
FPS: 56
FPS: 56
FPS: 57
FPS: 57
FPS: 56
FPS: 56
FPS: 57
FPS: 57
FPS: 56
FPS: 57
FPS: 56
FPS: 55
FPS: 53
FPS: 54
FPS: 52
FPS: 54
FPS: 54
FPS: 53
FPS: 54
FPS: 55
FPS: 53
FPS: 53
FPS: 55

4.2.3 显示视频

from IPython.display import clear_output,  display, HTML
from PIL import Image
import matplotlib.pyplot as plt
import time
import cv2
import base64

current_time = 0

# 图像处理函数
def processImg(img):
 # 画出一个框
#     cv2.rectangle(img, (500, 300), (800, 400), (0, 0, 255), 5, 1, 0)
 # 上下翻转
 # img= cv2.flip(img, 0)

 # 显示FPS
    
    global current_time
    if current_time == 0:
        current_time = time.time()
    else:
        last_time = current_time
        current_time = time.time()
        fps = 1. / (current_time - last_time)
        text = "FPS: %d" % int(fps)
        cv2.putText(img, text , (0,100), cv2.FONT_HERSHEY_TRIPLEX, 3.65, (255, 0, 0), 2)
#     img = cv2.resize(img,(1080,1080))
    img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    

    return img

def arrayShow(imageArray):
#     ret, png = cv2.imencode('.png', imageArray)
#     encoded = base64.b64encode(png)
#     return Image(data=encoded.decode('ascii'))
    return Image.fromarray(imageArray)


video = cv2.VideoCapture("./data/road.mp4")
small=1
while(True):
    try:
        clear_output(wait=True)
        ret, frame = video.read()
        if not ret:
            break
        lines, columns, _ = frame.shape
        frame = processImg(frame)
        frame = cv2.resize(frame, (int(columns / small), int(lines / small)))

        img = arrayShow(frame)

        display(img)
        # 控制帧率
        time.sleep(0.02)
    except KeyboardInterrupt:
        video.release()

在这里插入图片描述

5、模型性能统计测试

有12个模型完成训练,其中有部分也不收敛,可以看训练模型结果保存的png图片,模型测试顺序就不按什么顺序了

5.1 yolov4模型测试方法一

在这里插入图片描述

以下为map@iou=0.50.5的结果

%%bash
darknet detector map cfg/vechcle.data cfg/yolov4_vechcle.cfg backup/yolov4_vechcle_best.weights
net.optimized_memory = 0 
mini_batch = 1, batch = 16, time_steps = 1, train = 0 
Create CUDA-stream - 0 
 Create cudnn-handle 0 
nms_kind: greedynms (1), beta = 0.600000 
nms_kind: greedynms (1), beta = 0.600000 
nms_kind: greedynms (1), beta = 0.600000 

 seen 64, trained: 424 K-images (6 Kilo-batches_64) 

 calculation mAP (mean average precision)...
 Detection layer: 139 - type = 28 
 Detection layer: 150 - type = 28 
 Detection layer: 161 - type = 28 

 detections_count = 36911, unique_truth_count = 4058  
class_id = 0, name = bicycle, ap = 64.76%   	 (TP = 230, FP = 99) 
class_id = 1, name = bus, ap = 86.69%   	 (TP = 270, FP = 67) 
class_id = 2, name = car, ap = 74.02%   	 (TP = 1739, FP = 1002) 
class_id = 3, name = motorbike, ap = 73.81%   	 (TP = 350, FP = 140) 
class_id = 4, name = truck, ap = 64.48%   	 (TP = 326, FP = 263) 

 for conf_thresh = 0.25, precision = 0.65, recall = 0.72, F1-score = 0.68 
 for conf_thresh = 0.25, TP = 2915, FP = 1571, FN = 1143, average IoU = 51.59 % 

 IoU threshold = 50 %, used Area-Under-Curve for each unique Recall 
 mean average precision (mAP@0.50) = 0.727514, or 72.75 % 

Set -points flag:
 `-points 101` for MS COCO 
 `-points 11` for PascalVOC 2007 (uncomment `difficult` in voc.data) 
 `-points 0` (AUC) for ImageNet, PascalVOC 2010-2012, your custom dataset


 CUDA-version: 10010 (11020), cuDNN: 7.6.5, GPU count: 8  
 OpenCV version: 4.5.0
 0 : compute_capability = 700, cudnn_half = 0, GPU: Tesla V100-SXM2-32GB 
   layer   filters  size/strd(dil)      input                output
   0 conv     32       3 x 3/ 1    608 x 608 x   3 ->  608 x 608 x  32 0.639 BF
   1 conv     64       3 x 3/ 2    608 x 608 x  32 ->  304 x 304 x  64 3.407 BF
   2 conv     64       1 x 1/ 1    304 x 304 x  64 ->  304 x 304 x  64 0.757 BF
   3 route  1 		                           ->  304 x 304 x  64 
   4 conv     64       1 x 1/ 1    304 x 304 x  64 ->  304 x 304 x  64 0.757 BF
   5 conv     32       1 x 1/ 1    304 x 304 x  64 ->  304 x 304 x  32 0.379 BF
   6 conv     64       3 x 3/ 1    304 x 304 x  32 ->  304 x 304 x  64 3.407 BF
   7 Shortcut Layer: 4,  wt = 0, wn = 0, outputs: 304 x 304 x  64 0.006 BF
   8 conv     64       1 x 1/ 1    304 x 304 x  64 ->  304 x 304 x  64 0.757 BF
   9 route  8 2 	                           ->  304 x 304 x 128 
  10 conv     64       1 x 1/ 1    304 x 304 x 128 ->  304 x 304 x  64 1.514 BF
  11 conv    128       3 x 3/ 2    304 x 304 x  64 ->  152 x 152 x 128 3.407 BF
  12 conv     64       1 x 1/ 1    152 x 152 x 128 ->  152 x 152 x  64 0.379 BF
  13 route  11 		                           ->  152 x 152 x 128 
  14 conv     64       1 x 1/ 1    152 x 152 x 128 ->  152 x 152 x  64 0.379 BF
  15 conv     64       1 x 1/ 1    152 x 152 x  64 ->  152 x 152 x  64 0.189 BF
  16 conv     64       3 x 3/ 1    152 x 152 x  64 ->  152 x 152 x  64 1.703 BF
  17 Shortcut Layer: 14,  wt = 0, wn = 0, outputs: 152 x 152 x  64 0.001 BF
  18 conv     64       1 x 1/ 1    152 x 152 x  64 ->  152 x 152 x  64 0.189 BF
  19 conv     64       3 x 3/ 1    152 x 152 x  64 ->  152 x 152 x  64 1.703 BF
  20 Shortcut Layer: 17,  wt = 0, wn = 0, outputs: 152 x 152 x  64 0.001 BF
  21 conv     64       1 x 1/ 1    152 x 152 x  64 ->  152 x 152 x  64 0.189 BF
  22 route  21 12 	                           ->  152 x 152 x 128 
  23 conv    128       1 x 1/ 1    152 x 152 x 128 ->  152 x 152 x 128 0.757 BF
  24 conv    256       3 x 3/ 2    152 x 152 x 128 ->   76 x  76 x 256 3.407 BF
  25 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
  26 route  24 		                           ->   76 x  76 x 256 
  27 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
  28 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  29 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  30 Shortcut Layer: 27,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  31 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  32 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  33 Shortcut Layer: 30,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  34 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  35 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  36 Shortcut Layer: 33,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  37 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  38 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  39 Shortcut Layer: 36,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  40 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  41 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  42 Shortcut Layer: 39,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  43 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  44 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  45 Shortcut Layer: 42,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  46 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  47 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  48 Shortcut Layer: 45,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  49 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  50 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  51 Shortcut Layer: 48,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  52 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  53 route  52 25 	                           ->   76 x  76 x 256 
  54 conv    256       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 256 0.757 BF
  55 conv    512       3 x 3/ 2     76 x  76 x 256 ->   38 x  38 x 512 3.407 BF
  56 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
  57 route  55 		                           ->   38 x  38 x 512 
  58 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
  59 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  60 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  61 Shortcut Layer: 58,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  62 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  63 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  64 Shortcut Layer: 61,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  65 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  66 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  67 Shortcut Layer: 64,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  68 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  69 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  70 Shortcut Layer: 67,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  71 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  72 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  73 Shortcut Layer: 70,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  74 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  75 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  76 Shortcut Layer: 73,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  77 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  78 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  79 Shortcut Layer: 76,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  80 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  81 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  82 Shortcut Layer: 79,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  83 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  84 route  83 56 	                           ->   38 x  38 x 512 
  85 conv    512       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 512 0.757 BF
  86 conv   1024       3 x 3/ 2     38 x  38 x 512 ->   19 x  19 x1024 3.407 BF
  87 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
  88 route  86 		                           ->   19 x  19 x1024 
  89 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
  90 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
  91 conv    512       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x 512 1.703 BF
  92 Shortcut Layer: 89,  wt = 0, wn = 0, outputs:  19 x  19 x 512 0.000 BF
  93 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
  94 conv    512       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x 512 1.703 BF
  95 Shortcut Layer: 92,  wt = 0, wn = 0, outputs:  19 x  19 x 512 0.000 BF
  96 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
  97 conv    512       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x 512 1.703 BF
  98 Shortcut Layer: 95,  wt = 0, wn = 0, outputs:  19 x  19 x 512 0.000 BF
  99 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
 100 conv    512       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x 512 1.703 BF
 101 Shortcut Layer: 98,  wt = 0, wn = 0, outputs:  19 x  19 x 512 0.000 BF
 102 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
 103 route  102 87 	                           ->   19 x  19 x1024 
 104 conv   1024       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x1024 0.757 BF
 105 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 106 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 107 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 108 max                5x 5/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.005 BF
 109 route  107 		                           ->   19 x  19 x 512 
 110 max                9x 9/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.015 BF
 111 route  107 		                           ->   19 x  19 x 512 
 112 max               13x13/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.031 BF
 113 route  112 110 108 107 	                   ->   19 x  19 x2048 
 114 conv    512       1 x 1/ 1     19 x  19 x2048 ->   19 x  19 x 512 0.757 BF
 115 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 116 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 117 conv    256       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 256 0.095 BF
 118 upsample                 2x    19 x  19 x 256 ->   38 x  38 x 256
 119 route  85 		                           ->   38 x  38 x 512 
 120 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 121 route  120 118 	                           ->   38 x  38 x 512 
 122 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 123 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 124 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 125 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 126 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 127 conv    128       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 128 0.095 BF
 128 upsample                 2x    38 x  38 x 128 ->   76 x  76 x 128
 129 route  54 		                           ->   76 x  76 x 256 
 130 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
 131 route  130 128 	                           ->   76 x  76 x 256 
 132 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
 133 conv    256       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 256 3.407 BF
 134 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
 135 conv    256       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 256 3.407 BF
 136 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
 137 conv    256       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 256 3.407 BF
 138 conv     30       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x  30 0.089 BF
 139 yolo
[yolo] params: iou loss: ciou (4), iou_norm: 0.07, obj_norm: 1.00, cls_norm: 1.00, delta_norm: 1.00, scale_x_y: 1.20
 140 route  136 		                           ->   76 x  76 x 128 
 141 conv    256       3 x 3/ 2     76 x  76 x 128 ->   38 x  38 x 256 0.852 BF
 142 route  141 126 	                           ->   38 x  38 x 512 
 143 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 144 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 145 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 146 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 147 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 148 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 149 conv     30       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x  30 0.044 BF
 150 yolo
[yolo] params: iou loss: ciou (4), iou_norm: 0.07, obj_norm: 1.00, cls_norm: 1.00, delta_norm: 1.00, scale_x_y: 1.10
 151 route  147 		                           ->   38 x  38 x 256 
 152 conv    512       3 x 3/ 2     38 x  38 x 256 ->   19 x  19 x 512 0.852 BF
 153 route  152 116 	                           ->   19 x  19 x1024 
 154 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 155 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 156 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 157 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 158 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 159 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 160 conv     30       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x  30 0.022 BF
 161 yolo
[yolo] params: iou loss: ciou (4), iou_norm: 0.07, obj_norm: 1.00, cls_norm: 1.00, delta_norm: 1.00, scale_x_y: 1.05
Total BFLOPS 127.294 
avg_outputs = 1047336 
 Allocate additional workspace_size = 52.43 MB 
Loading weights from backup/yolov4_vechcle_best.weights...Done! Loaded 162 layers from weights-file 
1032Total Detection Time: 21 Seconds

要测map@iou=0.75

%%bash
darknet detector map cfg/vechcle.data cfg/yolov4_vechcle.cfg backup/yolov4_vechcle_best.weights -iou_thresh 0.75
net.optimized_memory = 0 
mini_batch = 1, batch = 16, time_steps = 1, train = 0 
Create CUDA-stream - 0 
 Create cudnn-handle 0 
nms_kind: greedynms (1), beta = 0.600000 
nms_kind: greedynms (1), beta = 0.600000 
nms_kind: greedynms (1), beta = 0.600000 

 seen 64, trained: 424 K-images (6 Kilo-batches_64) 

 calculation mAP (mean average precision)...
 Detection layer: 139 - type = 28 
 Detection layer: 150 - type = 28 
 Detection layer: 161 - type = 28 

 detections_count = 36911, unique_truth_count = 4058  
class_id = 0, name = bicycle, ap = 29.88%   	 (TP = 132, FP = 197) 
class_id = 1, name = bus, ap = 71.45%   	 (TP = 241, FP = 96) 
class_id = 2, name = car, ap = 44.90%   	 (TP = 1221, FP = 1520) 
class_id = 3, name = motorbike, ap = 39.21%   	 (TP = 221, FP = 269) 
class_id = 4, name = truck, ap = 37.34%   	 (TP = 239, FP = 350) 

 for conf_thresh = 0.25, precision = 0.46, recall = 0.51, F1-score = 0.48 
 for conf_thresh = 0.25, TP = 2054, FP = 2432, FN = 2004, average IoU = 39.15 % 

 IoU threshold = 75 %, used Area-Under-Curve for each unique Recall 
 mean average precision (mAP@0.75) = 0.445590, or 44.56 % 

Set -points flag:
 `-points 101` for MS COCO 
 `-points 11` for PascalVOC 2007 (uncomment `difficult` in voc.data) 
 `-points 0` (AUC) for ImageNet, PascalVOC 2010-2012, your custom dataset


 CUDA-version: 10010 (11020), cuDNN: 7.6.5, GPU count: 8  
 OpenCV version: 4.5.0
 0 : compute_capability = 700, cudnn_half = 0, GPU: Tesla V100-SXM2-32GB 
   layer   filters  size/strd(dil)      input                output
   0 conv     32       3 x 3/ 1    608 x 608 x   3 ->  608 x 608 x  32 0.639 BF
   1 conv     64       3 x 3/ 2    608 x 608 x  32 ->  304 x 304 x  64 3.407 BF
   2 conv     64       1 x 1/ 1    304 x 304 x  64 ->  304 x 304 x  64 0.757 BF
   3 route  1 		                           ->  304 x 304 x  64 
   4 conv     64       1 x 1/ 1    304 x 304 x  64 ->  304 x 304 x  64 0.757 BF
   5 conv     32       1 x 1/ 1    304 x 304 x  64 ->  304 x 304 x  32 0.379 BF
   6 conv     64       3 x 3/ 1    304 x 304 x  32 ->  304 x 304 x  64 3.407 BF
   7 Shortcut Layer: 4,  wt = 0, wn = 0, outputs: 304 x 304 x  64 0.006 BF
   8 conv     64       1 x 1/ 1    304 x 304 x  64 ->  304 x 304 x  64 0.757 BF
   9 route  8 2 	                           ->  304 x 304 x 128 
  10 conv     64       1 x 1/ 1    304 x 304 x 128 ->  304 x 304 x  64 1.514 BF
  11 conv    128       3 x 3/ 2    304 x 304 x  64 ->  152 x 152 x 128 3.407 BF
  12 conv     64       1 x 1/ 1    152 x 152 x 128 ->  152 x 152 x  64 0.379 BF
  13 route  11 		                           ->  152 x 152 x 128 
  14 conv     64       1 x 1/ 1    152 x 152 x 128 ->  152 x 152 x  64 0.379 BF
  15 conv     64       1 x 1/ 1    152 x 152 x  64 ->  152 x 152 x  64 0.189 BF
  16 conv     64       3 x 3/ 1    152 x 152 x  64 ->  152 x 152 x  64 1.703 BF
  17 Shortcut Layer: 14,  wt = 0, wn = 0, outputs: 152 x 152 x  64 0.001 BF
  18 conv     64       1 x 1/ 1    152 x 152 x  64 ->  152 x 152 x  64 0.189 BF
  19 conv     64       3 x 3/ 1    152 x 152 x  64 ->  152 x 152 x  64 1.703 BF
  20 Shortcut Layer: 17,  wt = 0, wn = 0, outputs: 152 x 152 x  64 0.001 BF
  21 conv     64       1 x 1/ 1    152 x 152 x  64 ->  152 x 152 x  64 0.189 BF
  22 route  21 12 	                           ->  152 x 152 x 128 
  23 conv    128       1 x 1/ 1    152 x 152 x 128 ->  152 x 152 x 128 0.757 BF
  24 conv    256       3 x 3/ 2    152 x 152 x 128 ->   76 x  76 x 256 3.407 BF
  25 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
  26 route  24 		                           ->   76 x  76 x 256 
  27 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
  28 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  29 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  30 Shortcut Layer: 27,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  31 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  32 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  33 Shortcut Layer: 30,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  34 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  35 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  36 Shortcut Layer: 33,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  37 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  38 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  39 Shortcut Layer: 36,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  40 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  41 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  42 Shortcut Layer: 39,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  43 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  44 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  45 Shortcut Layer: 42,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  46 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  47 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  48 Shortcut Layer: 45,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  49 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  50 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  51 Shortcut Layer: 48,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  52 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  53 route  52 25 	                           ->   76 x  76 x 256 
  54 conv    256       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 256 0.757 BF
  55 conv    512       3 x 3/ 2     76 x  76 x 256 ->   38 x  38 x 512 3.407 BF
  56 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
  57 route  55 		                           ->   38 x  38 x 512 
  58 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
  59 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  60 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  61 Shortcut Layer: 58,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  62 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  63 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  64 Shortcut Layer: 61,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  65 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  66 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  67 Shortcut Layer: 64,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  68 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  69 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  70 Shortcut Layer: 67,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  71 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  72 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  73 Shortcut Layer: 70,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  74 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  75 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  76 Shortcut Layer: 73,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  77 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  78 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  79 Shortcut Layer: 76,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  80 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  81 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  82 Shortcut Layer: 79,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  83 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  84 route  83 56 	                           ->   38 x  38 x 512 
  85 conv    512       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 512 0.757 BF
  86 conv   1024       3 x 3/ 2     38 x  38 x 512 ->   19 x  19 x1024 3.407 BF
  87 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
  88 route  86 		                           ->   19 x  19 x1024 
  89 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
  90 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
  91 conv    512       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x 512 1.703 BF
  92 Shortcut Layer: 89,  wt = 0, wn = 0, outputs:  19 x  19 x 512 0.000 BF
  93 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
  94 conv    512       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x 512 1.703 BF
  95 Shortcut Layer: 92,  wt = 0, wn = 0, outputs:  19 x  19 x 512 0.000 BF
  96 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
  97 conv    512       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x 512 1.703 BF
  98 Shortcut Layer: 95,  wt = 0, wn = 0, outputs:  19 x  19 x 512 0.000 BF
  99 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
 100 conv    512       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x 512 1.703 BF
 101 Shortcut Layer: 98,  wt = 0, wn = 0, outputs:  19 x  19 x 512 0.000 BF
 102 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
 103 route  102 87 	                           ->   19 x  19 x1024 
 104 conv   1024       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x1024 0.757 BF
 105 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 106 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 107 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 108 max                5x 5/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.005 BF
 109 route  107 		                           ->   19 x  19 x 512 
 110 max                9x 9/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.015 BF
 111 route  107 		                           ->   19 x  19 x 512 
 112 max               13x13/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.031 BF
 113 route  112 110 108 107 	                   ->   19 x  19 x2048 
 114 conv    512       1 x 1/ 1     19 x  19 x2048 ->   19 x  19 x 512 0.757 BF
 115 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 116 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 117 conv    256       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 256 0.095 BF
 118 upsample                 2x    19 x  19 x 256 ->   38 x  38 x 256
 119 route  85 		                           ->   38 x  38 x 512 
 120 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 121 route  120 118 	                           ->   38 x  38 x 512 
 122 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 123 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 124 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 125 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 126 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 127 conv    128       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 128 0.095 BF
 128 upsample                 2x    38 x  38 x 128 ->   76 x  76 x 128
 129 route  54 		                           ->   76 x  76 x 256 
 130 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
 131 route  130 128 	                           ->   76 x  76 x 256 
 132 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
 133 conv    256       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 256 3.407 BF
 134 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
 135 conv    256       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 256 3.407 BF
 136 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
 137 conv    256       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 256 3.407 BF
 138 conv     30       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x  30 0.089 BF
 139 yolo
[yolo] params: iou loss: ciou (4), iou_norm: 0.07, obj_norm: 1.00, cls_norm: 1.00, delta_norm: 1.00, scale_x_y: 1.20
 140 route  136 		                           ->   76 x  76 x 128 
 141 conv    256       3 x 3/ 2     76 x  76 x 128 ->   38 x  38 x 256 0.852 BF
 142 route  141 126 	                           ->   38 x  38 x 512 
 143 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 144 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 145 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 146 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 147 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 148 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 149 conv     30       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x  30 0.044 BF
 150 yolo
[yolo] params: iou loss: ciou (4), iou_norm: 0.07, obj_norm: 1.00, cls_norm: 1.00, delta_norm: 1.00, scale_x_y: 1.10
 151 route  147 		                           ->   38 x  38 x 256 
 152 conv    512       3 x 3/ 2     38 x  38 x 256 ->   19 x  19 x 512 0.852 BF
 153 route  152 116 	                           ->   19 x  19 x1024 
 154 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 155 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 156 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 157 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 158 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 159 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 160 conv     30       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x  30 0.022 BF
 161 yolo
[yolo] params: iou loss: ciou (4), iou_norm: 0.07, obj_norm: 1.00, cls_norm: 1.00, delta_norm: 1.00, scale_x_y: 1.05
Total BFLOPS 127.294 
avg_outputs = 1047336 
 Allocate additional workspace_size = 52.43 MB 
Loading weights from backup/yolov4_vechcle_best.weights...Done! Loaded 162 layers from weights-file 
1032Total Detection Time: 21 Seconds

5.2 yolov4模型性能测试方法二

新建results文件夹然后执行以下命令,对验证集批量产生结果:

%%bash
darknet detector valid cfg/vechcle.data cfg/yolov4_vechcle.cfg backup/yolov4_vechcle_best.weights
net.optimized_memory = 0 
mini_batch = 1, batch = 16, time_steps = 1, train = 0 
Create CUDA-stream - 0 
 Create cudnn-handle 0 
nms_kind: greedynms (1), beta = 0.600000 
nms_kind: greedynms (1), beta = 0.600000 
nms_kind: greedynms (1), beta = 0.600000 

 seen 64, trained: 424 K-images (6 Kilo-batches_64) 
 Detection layer: 139 - type = 28 
 Detection layer: 150 - type = 28 
 Detection layer: 161 - type = 28 


 CUDA-version: 10010 (11020), cuDNN: 7.6.5, GPU count: 8  
 OpenCV version: 4.5.0
results: Using default 'results'
 0 : compute_capability = 700, cudnn_half = 0, GPU: Tesla V100-SXM2-32GB 
   layer   filters  size/strd(dil)      input                output
   0 conv     32       3 x 3/ 1    608 x 608 x   3 ->  608 x 608 x  32 0.639 BF
   1 conv     64       3 x 3/ 2    608 x 608 x  32 ->  304 x 304 x  64 3.407 BF
   2 conv     64       1 x 1/ 1    304 x 304 x  64 ->  304 x 304 x  64 0.757 BF
   3 route  1 		                           ->  304 x 304 x  64 
   4 conv     64       1 x 1/ 1    304 x 304 x  64 ->  304 x 304 x  64 0.757 BF
   5 conv     32       1 x 1/ 1    304 x 304 x  64 ->  304 x 304 x  32 0.379 BF
   6 conv     64       3 x 3/ 1    304 x 304 x  32 ->  304 x 304 x  64 3.407 BF
   7 Shortcut Layer: 4,  wt = 0, wn = 0, outputs: 304 x 304 x  64 0.006 BF
   8 conv     64       1 x 1/ 1    304 x 304 x  64 ->  304 x 304 x  64 0.757 BF
   9 route  8 2 	                           ->  304 x 304 x 128 
  10 conv     64       1 x 1/ 1    304 x 304 x 128 ->  304 x 304 x  64 1.514 BF
  11 conv    128       3 x 3/ 2    304 x 304 x  64 ->  152 x 152 x 128 3.407 BF
  12 conv     64       1 x 1/ 1    152 x 152 x 128 ->  152 x 152 x  64 0.379 BF
  13 route  11 		                           ->  152 x 152 x 128 
  14 conv     64       1 x 1/ 1    152 x 152 x 128 ->  152 x 152 x  64 0.379 BF
  15 conv     64       1 x 1/ 1    152 x 152 x  64 ->  152 x 152 x  64 0.189 BF
  16 conv     64       3 x 3/ 1    152 x 152 x  64 ->  152 x 152 x  64 1.703 BF
  17 Shortcut Layer: 14,  wt = 0, wn = 0, outputs: 152 x 152 x  64 0.001 BF
  18 conv     64       1 x 1/ 1    152 x 152 x  64 ->  152 x 152 x  64 0.189 BF
  19 conv     64       3 x 3/ 1    152 x 152 x  64 ->  152 x 152 x  64 1.703 BF
  20 Shortcut Layer: 17,  wt = 0, wn = 0, outputs: 152 x 152 x  64 0.001 BF
  21 conv     64       1 x 1/ 1    152 x 152 x  64 ->  152 x 152 x  64 0.189 BF
  22 route  21 12 	                           ->  152 x 152 x 128 
  23 conv    128       1 x 1/ 1    152 x 152 x 128 ->  152 x 152 x 128 0.757 BF
  24 conv    256       3 x 3/ 2    152 x 152 x 128 ->   76 x  76 x 256 3.407 BF
  25 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
  26 route  24 		                           ->   76 x  76 x 256 
  27 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
  28 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  29 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  30 Shortcut Layer: 27,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  31 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  32 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  33 Shortcut Layer: 30,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  34 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  35 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  36 Shortcut Layer: 33,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  37 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  38 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  39 Shortcut Layer: 36,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  40 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  41 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  42 Shortcut Layer: 39,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  43 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  44 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  45 Shortcut Layer: 42,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  46 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  47 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  48 Shortcut Layer: 45,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  49 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  50 conv    128       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 128 1.703 BF
  51 Shortcut Layer: 48,  wt = 0, wn = 0, outputs:  76 x  76 x 128 0.001 BF
  52 conv    128       1 x 1/ 1     76 x  76 x 128 ->   76 x  76 x 128 0.189 BF
  53 route  52 25 	                           ->   76 x  76 x 256 
  54 conv    256       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 256 0.757 BF
  55 conv    512       3 x 3/ 2     76 x  76 x 256 ->   38 x  38 x 512 3.407 BF
  56 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
  57 route  55 		                           ->   38 x  38 x 512 
  58 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
  59 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  60 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  61 Shortcut Layer: 58,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  62 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  63 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  64 Shortcut Layer: 61,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  65 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  66 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  67 Shortcut Layer: 64,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  68 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  69 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  70 Shortcut Layer: 67,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  71 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  72 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  73 Shortcut Layer: 70,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  74 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  75 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  76 Shortcut Layer: 73,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  77 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  78 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  79 Shortcut Layer: 76,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  80 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  81 conv    256       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 256 1.703 BF
  82 Shortcut Layer: 79,  wt = 0, wn = 0, outputs:  38 x  38 x 256 0.000 BF
  83 conv    256       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 256 0.189 BF
  84 route  83 56 	                           ->   38 x  38 x 512 
  85 conv    512       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 512 0.757 BF
  86 conv   1024       3 x 3/ 2     38 x  38 x 512 ->   19 x  19 x1024 3.407 BF
  87 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
  88 route  86 		                           ->   19 x  19 x1024 
  89 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
  90 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
  91 conv    512       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x 512 1.703 BF
  92 Shortcut Layer: 89,  wt = 0, wn = 0, outputs:  19 x  19 x 512 0.000 BF
  93 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
  94 conv    512       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x 512 1.703 BF
  95 Shortcut Layer: 92,  wt = 0, wn = 0, outputs:  19 x  19 x 512 0.000 BF
  96 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
  97 conv    512       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x 512 1.703 BF
  98 Shortcut Layer: 95,  wt = 0, wn = 0, outputs:  19 x  19 x 512 0.000 BF
  99 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
 100 conv    512       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x 512 1.703 BF
 101 Shortcut Layer: 98,  wt = 0, wn = 0, outputs:  19 x  19 x 512 0.000 BF
 102 conv    512       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.189 BF
 103 route  102 87 	                           ->   19 x  19 x1024 
 104 conv   1024       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x1024 0.757 BF
 105 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 106 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 107 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 108 max                5x 5/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.005 BF
 109 route  107 		                           ->   19 x  19 x 512 
 110 max                9x 9/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.015 BF
 111 route  107 		                           ->   19 x  19 x 512 
 112 max               13x13/ 1     19 x  19 x 512 ->   19 x  19 x 512 0.031 BF
 113 route  112 110 108 107 	                   ->   19 x  19 x2048 
 114 conv    512       1 x 1/ 1     19 x  19 x2048 ->   19 x  19 x 512 0.757 BF
 115 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 116 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 117 conv    256       1 x 1/ 1     19 x  19 x 512 ->   19 x  19 x 256 0.095 BF
 118 upsample                 2x    19 x  19 x 256 ->   38 x  38 x 256
 119 route  85 		                           ->   38 x  38 x 512 
 120 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 121 route  120 118 	                           ->   38 x  38 x 512 
 122 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 123 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 124 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 125 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 126 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 127 conv    128       1 x 1/ 1     38 x  38 x 256 ->   38 x  38 x 128 0.095 BF
 128 upsample                 2x    38 x  38 x 128 ->   76 x  76 x 128
 129 route  54 		                           ->   76 x  76 x 256 
 130 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
 131 route  130 128 	                           ->   76 x  76 x 256 
 132 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
 133 conv    256       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 256 3.407 BF
 134 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
 135 conv    256       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 256 3.407 BF
 136 conv    128       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x 128 0.379 BF
 137 conv    256       3 x 3/ 1     76 x  76 x 128 ->   76 x  76 x 256 3.407 BF
 138 conv     30       1 x 1/ 1     76 x  76 x 256 ->   76 x  76 x  30 0.089 BF
 139 yolo
[yolo] params: iou loss: ciou (4), iou_norm: 0.07, obj_norm: 1.00, cls_norm: 1.00, delta_norm: 1.00, scale_x_y: 1.20
 140 route  136 		                           ->   76 x  76 x 128 
 141 conv    256       3 x 3/ 2     76 x  76 x 128 ->   38 x  38 x 256 0.852 BF
 142 route  141 126 	                           ->   38 x  38 x 512 
 143 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 144 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 145 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 146 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 147 conv    256       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x 256 0.379 BF
 148 conv    512       3 x 3/ 1     38 x  38 x 256 ->   38 x  38 x 512 3.407 BF
 149 conv     30       1 x 1/ 1     38 x  38 x 512 ->   38 x  38 x  30 0.044 BF
 150 yolo
[yolo] params: iou loss: ciou (4), iou_norm: 0.07, obj_norm: 1.00, cls_norm: 1.00, delta_norm: 1.00, scale_x_y: 1.10
 151 route  147 		                           ->   38 x  38 x 256 
 152 conv    512       3 x 3/ 2     38 x  38 x 256 ->   19 x  19 x 512 0.852 BF
 153 route  152 116 	                           ->   19 x  19 x1024 
 154 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 155 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 156 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 157 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 158 conv    512       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x 512 0.379 BF
 159 conv   1024       3 x 3/ 1     19 x  19 x 512 ->   19 x  19 x1024 3.407 BF
 160 conv     30       1 x 1/ 1     19 x  19 x1024 ->   19 x  19 x  30 0.022 BF
 161 yolo
[yolo] params: iou loss: ciou (4), iou_norm: 0.07, obj_norm: 1.00, cls_norm: 1.00, delta_norm: 1.00, scale_x_y: 1.05
Total BFLOPS 127.294 
avg_outputs = 1047336 
 Allocate additional workspace_size = 52.43 MB 
Loading weights from backup/yolov4_vechcle_best.weights...Done! Loaded 162 layers from weights-file 
Learning Rate: 0.001, Momentum: 0.949, Decay: 0.0005
eval: Using default 'voc'
4
8
12
16
20
24
28
32
36
40
44
48
52
56
60
64
68
72
76
80
84
88
92
96
100
104
108
112
116
120
124
128
132
136
140
144
148
152
156
160
164
168
172
176
180
184
188
192
196
200
204
208
212
216
220
224
228
232
236
240
244
248
252
256
260
264
268
272
276
280
284
288
292
296
300
304
308
312
316
320
324
328
332
336
340
344
348
352
356
360
364
368
372
376
380
384
388
392
396
400
404
408
412
416
420
424
428
432
436
440
444
448
452
456
460
464
468
472
476
480
484
488
492
496
500
504
508
512
516
520
524
528
532
536
540
544
548
552
556
560
564
568
572
576
580
584
588
592
596
600
604
608
612
616
620
624
628
632
636
640
644
648
652
656
660
664
668
672
676
680
684
688
692
696
700
704
708
712
716
720
724
728
732
736
740
744
748
752
756
760
764
768
772
776
780
784
788
792
796
800
804
808
812
816
820
824
828
832
836
840
844
848
852
856
860
864
868
872
876
880
884
888
892
896
900
904
908
912
916
920
924
928
932
936
940
944
948
952
956
960
964
968
972
976
980
984
988
992
996
1000
1004
1008
1012
1016
1020
1024
1028
1032
Total Detection Time: 42.000000 Seconds
%%bash
ls results
comp4_det_test_bicycle.txt
comp4_det_test_bus.txt
comp4_det_test_car.txt
comp4_det_test_motorbike.txt
comp4_det_test_truck.txt
%%bash
head -n 15 ./results/comp4_det_test_bicycle.txt
000000401980 0.839656 1.000000 207.924377 362.778381 427.000000
000000401980 0.617458 343.060028 215.706848 640.000000 427.000000
000000401980 0.137739 365.956360 266.341797 632.603455 427.000000
000000401980 0.048878 1.000000 113.423553 373.908722 427.000000
000000401980 0.027138 258.326660 183.985229 640.000000 427.000000
000000401980 0.005769 362.092041 282.595978 558.476379 422.788727
000000401980 0.005717 399.438232 134.345291 635.504150 427.000000
000000401980 0.004526 379.546814 323.268311 616.657593 427.000000
000000401980 0.002933 381.449188 354.378296 602.514404 427.000000
000000401980 0.002256 371.549042 362.315216 533.911743 427.000000
000000401980 0.002217 345.463776 288.028381 503.355743 419.107727
000000401980 0.001431 357.871887 364.965546 492.497253 427.000000
000000401980 0.001198 344.290649 252.155457 584.557373 409.533447
000000401980 0.001176 396.900513 374.411926 597.720337 426.435547
000000401980 0.001167 448.817688 215.300049 640.000000 427.000000

以上结果为:文件名 置信度 x y w h

然后将reval_voc_py3.py 和 voc_eval_py3.py放到和results同一级,具体内容要看源代码,然后执行以下代码,当然,我们的数据放到多个文件中,所以呢想要用这份代码需要改一下,暂时没必要

%%bash
python reval_voc_py.py --voc_dir VOCdevkit --year 2007 --image_set test --class ./cfg/vechcle.names --output_dir test

–voc_dir为数据集路径
年份为数据集文件夹时间 VOC2012
验证集文件名test.txt \VOC2017\ImageSets\Main
类名文件 my_Data.names
输出文件夹名 test
要自己新建test文件夹
获重结果后可以画Pr曲线,具体参见https://blog.csdn.net/weixin_45702256/article/details/119321994 这里就不再多做了,有需要再写

6、Anchor Box先验框聚类分析与修改

这个工作是对于有些数据,目标大小分部特殊,可以进行先验框计算,然后再进行操作

6.1 使用k-means聚类获得自己数据集的先验框大小

%%bash
darknet detector calc_anchors cfg/vechcle.data -num_of_clusters 9 -width 608 -height 608
IOPub data rate exceeded.
The Jupyter server will temporarily stop sending output
to the client in order to avoid crashing it.
To change this limit, set the config variable
`--ServerApp.iopub_data_rate_limit`.

Current values:
ServerApp.iopub_data_rate_limit=1000000.0 (bytes/sec)
ServerApp.rate_limit_window=3.0 (secs)

 CUDA-version: 10010 (11020), cuDNN: 7.6.5, GPU count: 8  
 OpenCV version: 4.5.0

以上命令可以放到shell中执行,结果大致如下,聚类结果保存在anchors.txt中,还有一个txt文档是counters_per_class.txt是用来保存每个分类有多少个框的,calc_anchors 计算是采用随机数初始的, 每次计算出的结果不太一样,可以多计算几次,从中选一个

root@884f85fe676b:/workspace/yolo_demo# darknet detector calc_anchors cfg/vechcle.data -num_of_clusters 9 -width 608 -height 608
 CUDA-version: 10010 (11020), cuDNN: 7.6.5, GPU count: 8
 OpenCV version: 4.5.0

 num_of_clusters = 9, width = 608, height = 608
 read labels from 24710 images
 loaded          image: 24710    box: 83514
 all loaded.

 calculating k-means++ ...

 iterations = 148


counters_per_class = 8488, 7101, 48015, 10024, 9886

 avg IoU = 60.70 %

Saving anchors to the file: anchors.txt
anchors =  21, 20,  48, 51, 114, 71,  75,150, 183,141, 174,287, 378,205, 342,387, 532,467

也可以通过python脚本来获取聚类值,gen_anchors.py有1个要修改的地方 第17~20行,改成自己的数值(416,608,832),本代码运行时间较长

%%bash
python gen_anchors.py -filelist cfg/train.txt -output_dir ./ -num_clusters 9
iter 1: dists = 606424.0129503558
iter 2: dists = 28501.70724020651
iter 3: dists = 9202.088097536196
iter 4: dists = 7301.728386852483
iter 5: dists = 6224.9412334696135
iter 6: dists = 5279.722984555354
iter 7: dists = 5562.663534725808
iter 8: dists = 4931.476816589927
iter 9: dists = 4582.141052156835
iter 10: dists = 4237.761034128802
iter 11: dists = 3811.5987488219857
iter 12: dists = 3385.8211120126666
iter 13: dists = 3128.362208530587
iter 14: dists = 3027.810199984304
iter 15: dists = 2944.035280637849
iter 16: dists = 2817.7684800290976
iter 17: dists = 2704.5393944211996
iter 18: dists = 2629.978295207829
iter 19: dists = 2575.2117409453163
iter 20: dists = 2421.31764750135
iter 21: dists = 2314.0972249341444
iter 22: dists = 2350.7272863928665
iter 23: dists = 2205.09210862319
iter 24: dists = 2134.9107794899633
iter 25: dists = 2104.1593729091696
iter 26: dists = 1940.8498872758787
iter 27: dists = 1834.6228507632038
iter 28: dists = 1811.5731609054133
iter 29: dists = 1627.7702032853927
iter 30: dists = 1531.1355089902463
iter 31: dists = 1409.230196049714
iter 32: dists = 1331.010186032567
iter 33: dists = 1208.6370858551452
iter 34: dists = 1123.245206224764
iter 35: dists = 1161.68323373432
iter 36: dists = 1120.3508068951528
iter 37: dists = 1008.2834759048279
iter 38: dists = 963.0480960732043
iter 39: dists = 950.378881907364
iter 40: dists = 831.754848143817
iter 41: dists = 686.1207305738013
iter 42: dists = 694.7501987488523
iter 43: dists = 702.9238748781272
iter 44: dists = 659.3914386177174
iter 45: dists = 633.547019651719
iter 46: dists = 640.8125997364422
iter 47: dists = 683.8596404460656
iter 48: dists = 687.8244288910233
iter 49: dists = 632.2069728745607
iter 50: dists = 601.268527901974
iter 51: dists = 609.7783036473509
iter 52: dists = 540.079659477649
iter 53: dists = 543.0395995298043
iter 54: dists = 495.1369586120734
iter 55: dists = 448.9205076839092
iter 56: dists = 451.9265305583567
iter 57: dists = 445.8676191578089
iter 58: dists = 402.46432092324363
iter 59: dists = 410.36114650634823
iter 60: dists = 419.39735795228376
iter 61: dists = 403.08377988541355
iter 62: dists = 412.2322869786506
iter 63: dists = 399.7808853033867
iter 64: dists = 381.6629861380409
iter 65: dists = 346.68236976678884
iter 66: dists = 331.25112404048065
iter 67: dists = 398.7653146460294
iter 68: dists = 393.37940779976736
iter 69: dists = 361.70151584083834
iter 70: dists = 406.57577465581545
iter 71: dists = 403.5997123802948
iter 72: dists = 340.94629204413224
iter 73: dists = 301.86688158653806
iter 74: dists = 257.1864677198275
iter 75: dists = 259.1410070090174
iter 76: dists = 240.5869313623183
iter 77: dists = 186.85374469748768
iter 78: dists = 175.38548852401078
iter 79: dists = 143.6900990340137
iter 80: dists = 110.76006074764805
iter 81: dists = 83.22622649077756
iter 82: dists = 55.18584562380896
iter 83: dists = 59.80965602938752
iter 84: dists = 77.19873303640345
iter 85: dists = 54.78921305941409
iter 86: dists = 54.67409173222138
iter 87: dists = 42.90874525206753
iter 88: dists = 40.227378132718876
iter 89: dists = 29.68499873332845
iter 90: dists = 18.584079634494078
iter 91: dists = 26.92546517042183
iter 92: dists = 35.22220507457459
iter 93: dists = 24.537504581685816
iter 94: dists = 36.78372233252653
iter 95: dists = 34.441230795207126
iter 96: dists = 28.150615086656074
iter 97: dists = 35.22806850106039
iter 98: dists = 40.16756408945783
iter 99: dists = 38.86809583100122
iter 100: dists = 39.63676909922949
iter 101: dists = 46.93281184950921
iter 102: dists = 46.37818424940942
iter 103: dists = 49.79067540958222
iter 104: dists = 36.70871166407363
iter 105: dists = 42.78608325243664
iter 106: dists = 44.13492693454714
iter 107: dists = 51.63791119384016
iter 108: dists = 44.10700932769693
iter 109: dists = 36.93207799817509
iter 110: dists = 31.51401685953906
iter 111: dists = 25.365938403004666
iter 112: dists = 30.2241754040899
iter 113: dists = 33.54497956233244
iter 114: dists = 51.8453403055046
iter 115: dists = 40.52132999542395
iter 116: dists = 46.43421406384323
iter 117: dists = 26.20199740820365
iter 118: dists = 28.371169115678182
iter 119: dists = 51.680930634064644
iter 120: dists = 27.613150324391142
iter 121: dists = 20.0054051188211
iter 122: dists = 15.713291231280182
iter 123: dists = 13.88971458665659
iter 124: dists = 12.134412851153034
iter 125: dists = 8.45830337535558
iter 126: dists = 7.339011068590554
iter 127: dists = 3.9050840814664607
iter 128: dists = 3.0161374966758867
iter 129: dists = 6.812149812531408
iter 130: dists = 9.321844914262861
iter 131: dists = 13.27738102866969
iter 132: dists = 17.73013320209525
iter 133: dists = 14.824107393686482
iter 134: dists = 18.203157425063424
iter 135: dists = 12.553729764703663
iter 136: dists = 9.403500749277438
iter 137: dists = 3.2910376110133313
Centroids =  [[0.83081278 0.81635949]
 [0.03474245 0.03378914]
 [0.21025277 0.12803264]
 [0.11241804 0.21235076]
 [0.22844756 0.35405258]
 [0.08352834 0.08000769]
 [0.73821317 0.48723731]
 [0.4138531  0.56776151]
 [0.45051463 0.24539772]]
Anchors =  [[ 0.66010657  0.64199361]
 [ 1.58703849  1.52014608]
 [ 2.13594285  4.03466442]
 [ 3.99480269  2.43262014]
 [ 4.34050358  6.72699893]
 [ 7.86320882 10.78746868]
 [ 8.55977798  4.66255677]
 [14.02605028  9.25750898]
 [15.78544279 15.51083033]]

centroids.shape (9, 2)

结果保存在anchors9.txt,内容是:
0.66,0.64, 1.59,1.52, 2.14,4.03, 3.99,2.43, 4.34,6.73, 7.86,10.79, 8.56,4.66, 14.03,9.26, 15.79,15.51
0.607339
第一行是anchors,使用时乘以32就可以拿到cfg中使用
第二行是iou平均值

6.2 修改cfg中anchors大小,然后进行重新训练

cfg文件中搜anchors可以查看。

总结

我们把整个文档做为使用darknet的教程,以下大概看一下文件结构

%%bash
tree -L 1 ./
./
├── anchors9.txt
├── anchors.txt
├── backup
├── cfg
├── chart_enetb0_vechcle.png
├── chart.png
├── chart_yolov3_tiny_vechcle.png
├── chart_yolov3_vechcle_mosaic.png
├── chart_yolov3_vechcle.png
├── chart_yolov4_csp_swish_vechcle.png
├── chart_yolov4_csp_vechcle.png
├── chart_yolov4_csp_x_swish_vechcle.png
├── chart_yolov4_p5_vechcle.png
├── chart_yolov4_p6_vechcle.png
├── chart_yolov4_tiny_vechcle.png
├── chart_yolov4_vechcle.png
├── chart_yolov4x_mish_vechcle.png
├── COCO
├── core.105601
├── core.122098
├── core.123505
├── core.156773
├── core.159716
├── core.176745
├── core.23172
├── core.33626
├── core.60037
├── core.62810
├── counters_per_class.txt
├── darknet_video.py
├── data
├── data_prepare.ipynb
├── gen_anchors.py
├── infer
├── logs
├── model_prepare.ipynb
├── results
├── reval_voc_py3.py
├── train_yolov3_enet.sh
├── train_yolov3_mosaic.sh
├── train_yolov3.sh
├── train_yolov3_tiny.sh
├── train_yolov4_csp.sh
├── train_yolov4_csp_swish.sh
├── train_yolov4_csp_x_swish.sh
├── train_yolov4_p5.sh
├── train_yolov4_p6.sh
├── train_yolov4.sh
├── train_yolov4_tiny.sh
├── train_yolov4x_mish.sh
├── VOCdevkit
└── voc_eval_py3.py

8 directories, 44 files

core文件大概是数据增强时的文件

%%bash
tree -L 1 ./data
./data
├── bus_station.mp4
├── car.jpg
├── labels
├── pred1.jpg
├── pred2.jpg
├── pred_bus_station.mp4
├── pred.jpg
├── pred.mp4
├── pred_road.mp4
├── pred_thred.mp4
└── road.mp4

1 directory, 10 files
%%bash
tree -L 1 ./cfg
./cfg
├── darknet53.conv.74
├── enetb0-coco.conv.132
├── enetb0_vechcle.cfg
├── libdarknet.so
├── train.txt
├── val.txt
├── vechcle.data
├── vechcle.names
├── yolov3-tiny.conv.11
├── yolov3_tiny_vechcle.cfg
├── yolov3_vechcle.cfg
├── yolov3_vechcle_mosaic.cfg
├── yolov4.conv.137
├── yolov4-csp.conv.142
├── yolov4-csp-swish.conv.164
├── yolov4_csp_swish_vechcle.cfg
├── yolov4_csp_vechcle.cfg
├── yolov4-csp-x-swish.conv.192
├── yolov4_csp_x_swish_vechcle.cfg
├── yolov4-p5.conv.232
├── yolov4_p5_vechcle.cfg
├── yolov4-p6.conv.289
├── yolov4_p6_vechcle.cfg
├── yolov4-tiny.conv.29
├── yolov4_tiny_vechcle.cfg
├── yolov4_vechcle.cfg
├── yolov4x-mish.conv.166
└── yolov4x_mish_vechcle.cfg

0 directories, 28 files
%%bash
tree -L 1 ./logs
./logs
├── yolov3_enet.log
├── yolov3.log
├── yolov3_mosaic.log
├── yolov3_tiny.log
├── yolov4_csp.log
├── yolov4_csp_swish.log
├── yolov4_csp_x_swish.log
├── yolov4.log
├── yolov4_p5.log
├── yolov4_p6.log
├── yolov4_tiny.log
└── yolov4x_mish.log

0 directories, 12 files

为了做为一个项目文件,我将会把所用没必要的文件删除如core开头的文件,还有训练的模型中非best,logs中的文件也就删了。为了代码能直接跑通,数据集不准备删除,无非大一些,保存到移动硬盘即可,

coco有20G,VOC有27个G,感觉也没必要,还是处理一下,coco,voc呢全删,想用就解码跑一下代码好了

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

【darknet】2、yolov4模型训练之模型训练 的相关文章

  • 微软RIA服务2009年7月预览版官方手册第2节(翻译:戴石麟)

    2 理解N层Silverlight应用项目 微软 NET RIA服务通过结合ASP NET和Silverlight平台来简化传统N层应用模式 应用逻辑写在中间层上 通过查询 更新 定制方法和服务操作来控制对数据的访问 NET RIA服务特性
  • Verilog入门学习笔记:Verilog基础语法梳理

    无论是学IC设计还是FPGA开发 Verilog都是最基本 最重要的必备技能 但任何一门编程语言的掌握都需要长期学习 并不是简简单单的随便读几本书 随便动动脑筋那么简单 Verilog是一门基于硬件的独特语言 由于它最终所实现的数字电路 具
  • netstat详解

    netstat是控制台命令 是一个监控TCP IP网络的非常有用的工具 它可以显示路由表 实际的网络连接以及每一个网络接口设备的状态信息 netstat可以用于显示与IP TCP UDP和ICMP协议相关的统计数据 一般用于检验本机各端口的
  • vb wor转存html,利用VB操作WORD的基本方法

    利用VB操作WORD的基本方法 通过查阅资料 自我实践 经实验通过 先引用word Application Dim MyWord As Word Application Dim MyWordBook As Word Document Set
  • Numpy:基础数据结构

    1 数组的基本属性 import numpy as np ar np array 1 2 3 4 5 6 7 print ar 输出数组 注意数组的格式 中括号 元素之间没有逗号 和列表区分 print ar ndim 输出数组维度的个数
  • Python @函数装饰器及用法(超级详细)转

    Python 内置的 3 种函数装饰器 分别是 staticmethod classmethod 和 property 其中 staticmethod classmethod 和 property 都是 Python 的内置函数 那么 我们

随机推荐

  • layui子弹框调用父弹框方法

    var thisFrame parent window document getElementById LAY layuiStampDuty1 getElementsByTagName iframe 0 id 获取父级弹框id值 var d
  • 【20220412】文献翻译4:交互中的手势和语言概述

    Gesture and speech in interaction An overview 1 简介 2 什么是共同语言 同声传译 手势 2 1 用手比划 2 2 用头做动作 3 语音和手势是交互的 3 1 交际环境中的手势 3 2 传递意
  • 双向链表

    双向就意味着对于每一个元素 都有两个方向的指向 因此从以下几个方面阐述双向链表 重要方法分析 全部代码 一 重要方法分析 这里的链表实现了我博客中的接口 ILinkedList 与结点 LinkedNode 具体的博客地址 http blo
  • 【Linux】VIM使用

    第一节 Vim常用操作 Vim没有菜单 只有命令 Vim的工作模式有三种 第一种 命令模式 vi vim 文件名 进入命令模式 不可以输入文字 只能识别命令 插入命令 a 在光标所在字符后插入 i 在光标所在字符前插入 o 在光标下插入新行
  • Vue基础精讲 —— Vue的组件之组件的定义、继承、自定义双向绑定、高级属性

    Vue组件基础定义 import Vue from vue const compoent props active type Boolean required true validator value return typeof value
  • UE4-蓝图基础:TimeLine

    一 概念 1 TimeLine 在一定时间内不断执行的一个蓝图节点 2 添加一个空白节点 函数讲解 Play 事件驱动 执行此事件时调用 Play from Start 从头开始执行事件 lt 事件在执行过程中未执行完毕 某一条件改变 事件
  • 回路电感详细介绍(环路电感)

    相比于硬件工程师 PCB工程师对环路电感更敏感 因为环路电感和走线强相关 不管是信号完整性还是电源完整性都涉及到这个概念 一旦电路结构确定 环路电感也随之确定 如果环路电感初期评估失误将会给后期改版带来巨大风险 更多资料请关注公众号 工程师
  • 操作系统 java模拟主存储器空间的分配和回收

    文章目录 实验原理 算法流程图 代码 结果 实验原理 模拟在可变分区管理方式下采用最先适应算法实现主存分配和回收 1 可变分区方式是按作业需要的主存空间大小来分割分区的 当要装入一个作业时 根据作业需要的主存量查看是否有足够的空闲空间 若有
  • 创建第一个Qt Widget项目

    创建第一个Qt Widget项目步骤 1 选择文件 Ctrl n 2 新建文件或项目 3 Qt Widget Application 4 输入项目名称FirstApplication 选择存储的位置 5 选择构建套件Desktop Qt Q
  • numpy一维数组永远为列向量

    import numpy as np a np array 1 3 4 5 print a shape a np transpose a print a shape print a a np ravel a print a shape pr
  • 静态分析简介

    一 程序静态分析简介 Program Static Analysis 程序静态分析简介 Program Static Analysis 是指在不运行代码的方式下 通过词法分析 语法分析 控制流 数据流分析等技术对程序代码进行扫描 验证代码是
  • 【mysql安装报错(已解决)】ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES)

    1 说在开头 我的 mysql 版本是 8 0 27 的 安装的时候 感觉每一步都没有错 但是就是不行 到连接本地数据库时 发现一直连不上 搞了好久 一直报下面的错 ERROR 1045 28000 Access denied for us
  • 一文带你聊聊MYSQL的锁和MVCC

    如果你觉得内容对你有帮助的话 不如给个赞 鼓励一下更新 本文内容总结自极客时间 MySQL实战45讲 专栏 LBCC 单版本控制 锁 基于锁的并发控制 这种方案比较简单粗暴 就是一个事务去读取一条数据的时候 就上锁 不允许其他事务来操作 当
  • 【Python自动化】生成带装饰图形的渐变背景文字封面

    Python自动化专栏 利用文字生成固定比例且带有装饰图形的封面 文章目录 一 背景介绍 二 功能介绍 效果预览 功能清单 三 过程拆解 1 渐变背景层 2 装饰图形层 3 半透明遮罩层 4 文字层 四 完整代码 参考文档 一 背景介绍 在
  • echarts地图map下钻到镇街、KMZ文件转GeoJson、合成自定义区域

    echarts 地图map下钻到镇街 KMZ文件转GeoJson 合成自定义区域 我们可以通过 http datav aliyun com tools atlas 阿里旗下的高德地图提供的api 可以获取到中国各个省份 区级 县级的json
  • NAT技术的主要实现方式及其对网络应用程序的使用影响

    网络地址转换 NAT 是接入广域网 WLAN 的一种技术 能够将私有 保留 地址转化为合法的IP地址 它被广泛应用于各种类型Internet接入方式和各种类型的网络中 NAT的实现方式有三种 静态转换 动态转换和端口多路复用 静态转换设置起
  • Linux审计与日志安全加固

    审计和日志服务配置 auditctl 审计数据配置 日志文件最大参数 在储存策略 etc audit audit conf 中配置max log file
  • 高德地图精确查找与定位RegeocodeQuery与GeocodeQuery

    根据输入的字符串精确查找位置 用GeocodeQuery查找坐标 然后根据获取到的坐标 用RegeocodeQuery查询地址 例子中用了两个页面 一个是显示地址信息及定位的页面 另一个是搜索页面 点击搜索结果返回显示页面 显示信息并定位
  • iOS经典面试题总结--内存管理

    2019独角兽企业重金招聘Python工程师标准 gt gt gt 我根据自己的情况做了一下总结 答案是我总结的 如有答的不好的地方 希望批评指正以及交流 谢谢 内存管理 1 什么是ARC ARC是automatic reference c
  • 【darknet】2、yolov4模型训练之模型训练

    文章目录 1 进行模型训练数据准备 1 1 划分训练和验证集 1 2 将数据标注格式转换为YOLO格式 2 修改配置文件 2 1 新建cfg vechle names 2 2 新建cfg vechle data 2 3 根据所选模型的不同