在特征图上按照高斯公式计算置信度

centerNet中计算分类target的方法就是使用高斯公式

对于每一个gt_box,我们首先得到中心点,然后就可以根据这个中心点和特征图的长宽计算置信度图了

最后算出来的置信度是以中心点为圆心,整个特征图外接圆的半径为半径的高斯分布置信度

import torch
import numpy as np
import matplotlib.pyplot as plt
import math
import time

# 计算矩形外接圆的半径
# R = sqrt(h^2 + w^2)/2
def get_radius(height, width):
    r = math.sqrt(height**2 + width**2) / 2
    return int(r)

def gaussian2d(shape, sigma=1):
    shape[0] = int(shape[0])
    shape[1] = int(shape[1])
    mask_gaussian = torch.zeros(shape[0], shape[1])
    x, y = shape[0]//2, shape[1]//2
    quanzhong = 1/(math.sqrt(2*3.1415)*sigma)
    fenmu = 2*sigma**2
    for i in range(shape[0]):
        for j in range(shape[1]):
            value = math.exp(-((i-x)**2+(j-y)**2)/fenmu)
            mask_gaussian[i][j] = quanzhong*value
    return mask_gaussian


# heatmap说特征图,center记录的是中心点的坐标
# r
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值