陆续总结中
BN (BatchNormalization)
主要作用:
- 缓解梯度消失问题
- 加快训练速度
对于一个输入大小为N*C*H*W的特征,在NHW的层面上进行归一化,C的维度是保留的,而对于LN(Layer Normalization),是在CHW的层面上进行归一化。

对于两者之间的差异,文字的解释远没有公式的总结来的直接。
BN层训练和测试过程的差异
在训练的过程中,数据集被分成一个个mini-batch,我们对每个batch都能够计算得到均值和方差;在测试阶段,由于测试集是一个个进入网络,所以此时没办法算均值和方差,那么只能借用训练集的信息。
在训练时,将每个mini-batch的均值和方差记住,总体均值便用每个batch的均值的期望来估计,总体方差便用每个batch的方差的无偏估计代替。从而得到了,用以测试的均值和方差。
整个训练集的均值和方差的值,一般是在训练的同时用移动平均法来求。
模型在训练集上的表现和在测试集上的表现差异较大
出现这种情况的原因一般是模型发生了过拟合;
- 解决过拟合最好的方法,是增加数据,数据是深度学习模型的燃料,数据越多喂出来的模型,其性能往往也越好。增加数据,是一种理想的情况,很多时候想要更多的数据纯属想pi吃;
非极大值抑制(Non-maximum suppression, NMS)
代码实现
def nms(bounding_boxes, confidence_scores, thred):
if not bounding_boxes:
return [],[]
boxes = np.array(bounding_boxes)
start_x = boxes[:,0]
start_y = boxes[:,1]
end_x = boxes[:,2]
end_y = boxes[:,3]
scores = np.array(confidence_scores)
picked_boxes = []
picked_score = []
areas = (end_x - start_x + 1) * (end_y - start_y + 1)
order = np.argsort(scores)
while order.size > 0:
index = order[-1]
picked_boxes.append(bounding_boxes[index])
picked_score.append(confidence_scores[index])
x1 = np.maximum(start_x[index], start_x[order[:-1]])
x2 = np.minimum(end_x[index], end_x[order[:-1]])
y1 = np.maximum(start_y[index], start_y[order[:-1]])
y2 = np.minimum(end_y[index], end_y[order[:-1]])
w = np.maximum(0.0, x2 - x1 + 1)
h = np.maximum(0.0, y2 - y1 + 1)
intersection = w * h
ratio = intersection / (areas[index] + areas[order[:-1]] - intersection)
# 保留小于阈值的框的索引
left = np.where(ratio < thred)
order = order[left]
return picked_boxes, picked_score