https://arxiv.org/abs/1904.07850
https://github.com/xingyizhou/CenterNet
backbone:
a:Hourglass 沙漏网络,未对其修改
b:带转置卷积的resnet + deformable conv
c:DLA-34语义分割网络
d:DLA-34 + FPN结构
全卷积网络直接得到4倍下采样的热力图,不需要提前设定anchors, 大大减少了网络参数量和计算量。热力图的通道数等于要检测的目标类别数,热力图的前100个峰值作为网络提取的目标中心点,然后设定一个阈值进行筛选得到最终的目标中心点。
Centernet 中所有的上采样前都有deformable卷积,这种卷积的作用就是使得网络的感受野变得更加精确,而不是限定为3*3的矩形卷积框内。同时4倍的下采样feature map 比一般网络的分辨率高很多,所有不需要进行多尺度预测和特征金字塔也可以同时较好的检测大小目标。
Centernet 不需要NMS,因为所有检测的中心点是由热力图的峰值得到的,这样就已经有一个非极大值抑制的过程,而且NMS是十分耗时的,所以Centernet才能又好又快。
Centernet 采用编码解码的全卷积骨干网络,上采样用到的是转置卷积,与一般上采样中的双线性差值有很大区别,转置卷积可以更好的还原图像的语义信息和位置信息。
loss:
损失函数包括三部分,
1.heatmap损失,来自修改过的focal loss
2.height width的预测损失,采用 l1 损失
3.中心点的offset损失,采用 l1 损失
import tensorflow as tf
def g_focal_loss(hm_pred, hm_true):
pos_mask = tf.cast(tf.equal(hm_true, 1), tf.float32)
neg_mask = tf.cast(tf.less(hm_true, 1), tf.float32) ###tf.less(x<y)
neg_weights = tf.pow(1 - hm_true, 4)
# print('hm_pred:',hm_pred.shape)
# print('hm_true:',hm_true.shape)
pos_loss = -tf.math.log(tf.clip_by_value(hm_pred, 1e-4, 1. - 1e-4)) * tf.pow(1 - hm_pred, 2) * pos_mask
neg_loss = -tf.math.log(tf.clip_by_value(1 - hm_pred, 1e-4, 1. - 1e-4)) * tf.pow(hm_pred, 2) * neg_weights * neg_mask
num_pos = tf.reduce_sum(pos_mask)
pos_loss = tf.reduce_sum(pos_loss)
neg_loss = tf.reduce_sum(neg_loss)
cls_loss = tf.cond(tf.greater(num_pos, 0), lambda: (pos_loss + neg_loss) / num_pos, lambda: neg_loss)
return cls_loss
def reg_l1_loss(y_pred, y_true, mask):
mask = tf.tile(tf.expand_dims(mask, axis=-1), (1, 1, 1, 2)) ###将不为1的维度复制n份
total_loss = tf.reduce_sum(tf.abs(y_true * mask - y_pred * mask))
reg_loss = total_loss / (tf.reduce_sum(mask) + 1e-4)
return reg_loss
链接:https://www.jianshu.com/p/d5d7cd7ad200