分類器
darknet-53(52層卷積層+1FC )

實作每秒最高的測量浮點運算。這意味着網絡結構可以更好地利用GPU,進而使其評估效率更高,速度更快。
Darknet-53比ResNet-101更好,速度更快1:5倍。 Darknet-53與ResNet-152具有相似的性能,速度提高2倍。
多尺度預測
坐标預測: bbox 預測仍是yolov2的使用次元聚類(dimension clusters )作為anchor boxes來預測邊界框. 在訓練期間,我們使用平方誤差損失的總和。
對象分數: YOLOv3使用邏輯回歸預測每個邊界框(bounding box)的對象分數。 如果先前的邊界框比之前的任何其他邊界框重疊ground truth對象,則該值應該為1。如果以前的邊界框不是最好的,但是确實将ground truth對象重疊了一定的門檻值以上,我們會忽略這個預測,按照[15]進行。我們使用門檻值0.5。與[15]不同,我們的系統隻為每個ground truth對象配置設定一個邊界框。如果先前的邊界框未配置設定給grounding box對象,則不會對坐标或類别預測造成損失。
類别預測: 每個框使用多标簽分類來預測邊界框可能包含的類。在訓練過程中,使用二進制交叉熵損失來進行類别預測。
多尺度: YOLOv3預測3種不同尺度的框(boxes),每個尺度的3個框,是以,
張量為
N×N×[3 *(4 + 1 + 80)]
。
網絡會在預測三種尺度的特征N分别為13,26,52,分别對應各三種anchor
(116×90); (156×198); (373×326)
(30×61);(62×45); (59×119);
(10×13);(16×30);(33×23);
(大尺度用小anchor,提高小目辨別别能力)
預測tx ty tw th
- 對tx和ty進行sigmoid,并加上對應的offset(下圖Cx, Cy)
- 對th和tw進行exp,并乘以對應的錨點值
- 對tx,ty,th,tw乘以對應的步幅,即:416/13, 416 ⁄ 26, 416 ⁄ 52
- 最後,使用sigmoid對Objectness和Classes confidence進行sigmoid得到0~1的機率,之是以用sigmoid取代之前版本的softmax,原因是softmax會擴大最大類别機率值而抑制其他類别機率值
layer filters size input output
0 conv 32 3 x 3 / 1 416 x 416 x 3 -> 416 x 416 x 32
1 conv 64 3 x 3 / 2 416 x 416 x 32 -> 208 x 208 x 64
2 conv 32 1 x 1 / 1 208 x 208 x 64 -> 208 x 208 x 32
3 conv 64 3 x 3 / 1 208 x 208 x 32 -> 208 x 208 x 64
4 Shortcut Layer: 1
5 conv 128 3 x 3 / 2 208 x 208 x 64 -> 104 x 104 x 128
6 conv 64 1 x 1 / 1 104 x 104 x 128 -> 104 x 104 x 64
7 conv 128 3 x 3 / 1 104 x 104 x 64 -> 104 x 104 x 128
8 Shortcut Layer: 5
9 conv 64 1 x 1 / 1 104 x 104 x 128 -> 104 x 104 x 64
10 conv 128 3 x 3 / 1 104 x 104 x 64 -> 104 x 104 x 128
11 Shortcut Layer: 8
12 conv 256 3 x 3 / 2 104 x 104 x 128 -> 52 x 52 x 256
13 conv 128 1 x 1 / 1 52 x 52 x 256 -> 52 x 52 x 128
14 conv 256 3 x 3 / 1 52 x 52 x 128 -> 52 x 52 x 256
15 Shortcut Layer: 12
16 conv 128 1 x 1 / 1 52 x 52 x 256 -> 52 x 52 x 128
17 conv 256 3 x 3 / 1 52 x 52 x 128 -> 52 x 52 x 256
18 Shortcut Layer: 15
19 conv 128 1 x 1 / 1 52 x 52 x 256 -> 52 x 52 x 128
20 conv 256 3 x 3 / 1 52 x 52 x 128 -> 52 x 52 x 256
21 Shortcut Layer: 18
22 conv 128 1 x 1 / 1 52 x 52 x 256 -> 52 x 52 x 128
23 conv 256 3 x 3 / 1 52 x 52 x 128 -> 52 x 52 x 256
24 Shortcut Layer: 21
25 conv 128 1 x 1 / 1 52 x 52 x 256 -> 52 x 52 x 128
26 conv 256 3 x 3 / 1 52 x 52 x 128 -> 52 x 52 x 256
27 Shortcut Layer: 24
28 conv 128 1 x 1 / 1 52 x 52 x 256 -> 52 x 52 x 128
29 conv 256 3 x 3 / 1 52 x 52 x 128 -> 52 x 52 x 256
30 Shortcut Layer: 27
31 conv 128 1 x 1 / 1 52 x 52 x 256 -> 52 x 52 x 128
32 conv 256 3 x 3 / 1 52 x 52 x 128 -> 52 x 52 x 256
33 Shortcut Layer: 30
34 conv 128 1 x 1 / 1 52 x 52 x 256 -> 52 x 52 x 128
35 conv 256 3 x 3 / 1 52 x 52 x 128 -> 52 x 52 x 256
36 Shortcut Layer: 33
37 conv 512 3 x 3 / 2 52 x 52 x 256 -> 26 x 26 x 512
38 conv 256 1 x 1 / 1 26 x 26 x 512 -> 26 x 26 x 256
39 conv 512 3 x 3 / 1 26 x 26 x 256 -> 26 x 26 x 512
40 Shortcut Layer: 37
41 conv 256 1 x 1 / 1 26 x 26 x 512 -> 26 x 26 x 256
42 conv 512 3 x 3 / 1 26 x 26 x 256 -> 26 x 26 x 512
43 Shortcut Layer: 40
44 conv 256 1 x 1 / 1 26 x 26 x 512 -> 26 x 26 x 256
45 conv 512 3 x 3 / 1 26 x 26 x 256 -> 26 x 26 x 512
46 Shortcut Layer: 43
47 conv 256 1 x 1 / 1 26 x 26 x 512 -> 26 x 26 x 256
48 conv 512 3 x 3 / 1 26 x 26 x 256 -> 26 x 26 x 512
49 Shortcut Layer: 46
50 conv 256 1 x 1 / 1 26 x 26 x 512 -> 26 x 26 x 256
51 conv 512 3 x 3 / 1 26 x 26 x 256 -> 26 x 26 x 512
52 Shortcut Layer: 49
53 conv 256 1 x 1 / 1 26 x 26 x 512 -> 26 x 26 x 256
54 conv 512 3 x 3 / 1 26 x 26 x 256 -> 26 x 26 x 512
55 Shortcut Layer: 52
56 conv 256 1 x 1 / 1 26 x 26 x 512 -> 26 x 26 x 256
57 conv 512 3 x 3 / 1 26 x 26 x 256 -> 26 x 26 x 512
58 Shortcut Layer: 55
59 conv 256 1 x 1 / 1 26 x 26 x 512 -> 26 x 26 x 256
60 conv 512 3 x 3 / 1 26 x 26 x 256 -> 26 x 26 x 512
61 Shortcut Layer: 58
62 conv 1024 3 x 3 / 2 26 x 26 x 512 -> 13 x 13 x1024
63 conv 512 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 512
64 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024
65 Shortcut Layer: 62
66 conv 512 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 512
67 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024
68 Shortcut Layer: 65
69 conv 512 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 512
70 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024
71 Shortcut Layer: 68
72 conv 512 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 512
73 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024
74 Shortcut Layer: 71
75 conv 512 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 512
76 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024
77 conv 512 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 512
78 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024
79 conv 512 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 512
80 conv 1024 3 x 3 / 1 13 x 13 x 512 -> 13 x 13 x1024
81 conv 18 1 x 1 / 1 13 x 13 x1024 -> 13 x 13 x 18
82 detection
83 route 79
84 conv 256 1 x 1 / 1 13 x 13 x 512 -> 13 x 13 x 256
85 upsample 2x 13 x 13 x 256 -> 26 x 26 x 256
86 route 85 61
87 conv 256 1 x 1 / 1 26 x 26 x 768 -> 26 x 26 x 256
88 conv 512 3 x 3 / 1 26 x 26 x 256 -> 26 x 26 x 512
89 conv 256 1 x 1 / 1 26 x 26 x 512 -> 26 x 26 x 256
90 conv 512 3 x 3 / 1 26 x 26 x 256 -> 26 x 26 x 512
91 conv 256 1 x 1 / 1 26 x 26 x 512 -> 26 x 26 x 256
92 conv 512 3 x 3 / 1 26 x 26 x 256 -> 26 x 26 x 512
93 conv 18 1 x 1 / 1 26 x 26 x 512 -> 26 x 26 x 18
94 detection
95 route 91
96 conv 128 1 x 1 / 1 26 x 26 x 256 -> 26 x 26 x 128
97 upsample 2x 26 x 26 x 128 -> 52 x 52 x 128
98 route 97 36
99 conv 128 1 x 1 / 1 52 x 52 x 384 -> 52 x 52 x 128
100 conv 256 3 x 3 / 1 52 x 52 x 128 -> 52 x 52 x 256
101 conv 128 1 x 1 / 1 52 x 52 x 256 -> 52 x 52 x 128
102 conv 256 3 x 3 / 1 52 x 52 x 128 -> 52 x 52 x 256
103 conv 128 1 x 1 / 1 52 x 52 x 256 -> 52 x 52 x 128
104 conv 256 3 x 3 / 1 52 x 52 x 128 -> 52 x 52 x 256
105 conv 18 1 x 1 / 1 52 x 52 x 256 -> 52 x 52 x 18
106 detection
cfg 層定義
region層:參數anchors指定kmeans計算出來的anchor box的長寬的絕對值(與網絡輸入大小相關),num參數為anchor box的數量,
另外還有bias_match,classes,coords等參數.在parser.c代碼中的parse_region函數中解析這些參數,并儲存在region_layer.num參數儲存在l.n變量中;anchors儲存在l.biases數組中.region_layer的前向傳播中使用for(n = 0; n < l.n; ++n)這樣的語句,是以,如果在配置檔案中anchors的數量大于num時,僅使用前num個,小于時記憶體越界.
region層的輸入和輸出大小與前一層(1x1 conv)的輸出大小和網絡的輸入大小相關.
Detection層: 坐标及類别結果輸出層.
shortcut 層:
同樣尺寸的相加add,也就是把兩個c h w都相同的兩個層相加成一個相同c h w的層。
[shortcut]
from=-3 #将本層(-1)與往前數第三個層相加
route層
concat層,合并一起,加厚
route層它的參數 layers 有一個或兩個值。當隻有一個值時,它輸出這一層通過該值索引的特征圖。在我們的實驗中設定為了-4,是以層級将輸出路由層之前第四個層的特征圖。
當參數有兩個值時,它将傳回由這兩個值索引的拼接特征圖。
使用k-means聚類來确定我們的邊界框的先驗。我們隻是選擇了9個聚類(clusters)和3個尺度(scales),然後在整個尺度上均勻分割聚類。在COCO資料集上,9個聚類是:(10×13);(16×30);(33×23);(30×61);(62×45); (59×119); (116×90); (156×198); (373×326)。
訓練
https://blog.csdn.net/weixin_42078618/article/details/87787919
xy_loss = object_mask * box_loss_scale * K.binary_crossentropy(raw_true_xy, raw_pred[..., 0:2], from_logits=True)
wh_loss = object_mask * box_loss_scale * 0.5 * K.square(raw_true_wh - raw_pred[..., 2:4])
confidence_loss = object_mask * K.binary_crossentropy(object_mask, raw_pred[..., 4:5], from_logits=True) + \
(1 - object_mask) * K.binary_crossentropy(object_mask, raw_pred[..., 4:5], from_logits=True) * ignore_mask
class_loss = object_mask * K.binary_crossentropy(true_class_probs, raw_pred[..., 5:], from_logits=True)
函數一共分為四部分
(1)計算xy(物體中心坐标)的損失
object_mask就是置信度
box_loss_scale可以了解為2-w*h
raw_true_xy就是真實的xy坐标點了
raw_pred[…, :2]是xy預測坐标點
是以第一個式子想對還挺直覺,簡化為:
bool是置信度
其中bce是xy值的二值交叉熵損失,這個值越小整個損失值越小
bool*(2-areaPred)的值越小,則需要在確定置信度(bool)的情況下,areaPred需要越大
是以,這部分損失主要優化xy的預測值(bce)和置信度(bool)以及wh回歸值(areaPred)
(2)計算wh(anchor長寬回歸值)的損失
跟(1)式 的差距就在最後一項,是以我們直接簡化之:
在確定置信度(bool)的情況下,areaPred需要越大,wh需要盡可能靠近真實值wh
這部分主要優化置信度(bool)wh回歸值(areaPred、whTrue)
(3)計算置信度損失(前背景)損失
confidence_loss:
YOLOv2中,總共有845個anchor_boxes,與true_boxes比對的用于預測pred_boxes,未與true_boxes比對的anchor_boxes用于預測background。
objects_loss(true_boxes所比對的anchor_boxes)
與true_boxes所比對的anchor_boxes去和預測的pred_boxes計算objects_loss。
no_objects_loss(true_boxes未比對的anchor_boxes)
1、未與true_boxes所比對的anchor_boxes中,若與true_boxes的IOU>0.6,則無需計算loss。
2、未與true_boxes所比對的anchor_boxes中,若與true_boxes的IOU<0.6,則計算no_objects_loss。
jianshu.com/p/032b1eecb335
簡化為:
其中bool為置信度,bce為預測值和實際置信度的二值交叉熵,ignore表示iou低于一定門檻值的但确實存在的物體,相當于frcnn中的中性點位,既不是前景也不是背景,是忽略的,暫時不計的。
在確定置信度(bool)的情況下,預測值需要盡可能靠近真實值,同時沒有物體的部分需要盡可能靠近背景真實值,同時乘以相應的需要忽略點位
這部分主要優化置信度,同時縮減了檢測的目标量級
(4)計算類别損失
這個不用多說了,直接就是置信度乘上個多分類的交叉熵
這部分優化置信度損失和類别損失
(5)最後,總損失為所有損失之和相加
xy_loss = K.sum(xy_loss) / mf
wh_loss = K.sum(wh_loss) / mf
confidence_loss = K.sum(confidence_loss) / mf
class_loss = K.sum(class_loss) / mf
loss += xy_loss + wh_loss + confidence_loss + class_loss
訓練
https://blog.csdn.net/shanlepu6038/article/details/84778770
使用多尺度訓練,大量的data augmentation,batch normalization
ref
http://www.cnblogs.com/makefile/p/YOLOv3.html
https://blog.csdn.net/qq_37541097/article/details/81214953