CenterNet:Objects as Points代码解析:通过高斯函数画热点图

Posted 萌萌滴太阳

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CenterNet:Objects as Points代码解析:通过高斯函数画热点图相关的知识,希望对你有一定的参考价值。

原理参考https://zhuanlan.zhihu.com/p/96856635
确定高斯半径

def gaussian_radius(det_size, min_overlap=0.7):
 height, width = det_size

 a1  = 1
 b1  = (height + width)
 c1  = width * height * (1 - min_overlap) / (1 + min_overlap)
 sq1 = np.sqrt(b1 ** 2 - 4 * a1 * c1)
 r1  = (b1 + sq1) / 2

 a2  = 4
 b2  = 2 * (height + width)
 c2  = (1 - min_overlap) * width * height
 sq2 = np.sqrt(b2 ** 2 - 4 * a2 * c2)
 r2  = (b2 + sq2) / 2

 a3  = 4 * min_overlap
 b3  = -2 * min_overlap * (height + width)
 c3  = (min_overlap - 1) * width * height
 sq3 = np.sqrt(b3 ** 2 - 4 * a3 * c3)
 r3  = (b3 + sq3) / 2
 return min(r1, r2, r3)

通过def draw_umich_gaussian画出我们想要的heatmap.

def draw_umich_gaussian(heatmap, center, radius, k=1):
  diameter = 2 * radius + 1
  gaussian = gaussian2D((diameter, diameter), sigma=diameter / 6)
  
  x, y = int(center[0]), int(center[1])

  height, width = heatmap.shape[0:2]
  #防止所画的高斯区域超过heatmap  
  left, right = min(x, radius), min(width - x, radius + 1)
  top, bottom = min(y, radius), min(height - y, radius + 1)

  #masked_heatmap(标记的热点图):高斯圆的外切矩形,因为前面heatmap用0初始化,所以masked_heatmap中的值为0
  masked_heatmap  = heatmap[y - top:y + bottom, x - left:x + right]
  masked_gaussian = gaussian[radius - top:radius + bottom, radius - left:radius + right]
  if min(masked_gaussian.shape) > 0 and min(masked_heatmap.shape) > 0: # TODO debug
    #因为masked_heatmap中的值为0,所画出的高斯图masked_gaussian又大于0,所以这里选两者最大的,就是将高斯图masked_gaussian画在heatmap上。
    np.maximum(masked_heatmap, masked_gaussian * k, out=masked_heatmap)
  return heatmap

以上是关于CenterNet:Objects as Points代码解析:通过高斯函数画热点图的主要内容,如果未能解决你的问题,请参考以下文章

目标检测anchor-free框架:CenterNet :Objects as Points

CenterNet:Objects as Points代码解析:通过高斯函数画热点图

MySQL通过POIN数据类型查询指定范围内数据

自主研发平台POIN4.2揭秘系列 --分布式事务

Random - circle

201403-2窗口