def make_gaussian_batch(heatmaps, size, fwhm):
""" Make a square gaussian kernel.
size is the length of a side of the square
fwhm is full-width-half-maximum, which
can be thought of as an effective radius.
"""
stride = heatmaps.shape[1] // size
batch_datum = np.zeros(shape=(heatmaps.shape[0], size, size, heatmaps.shape[3]))
for data_num in range(heatmaps.shape[0]):
for joint_num in range(heatmaps.shape[3] - 1):
heatmap = heatmaps[data_num, :, :, joint_num]
center = np.unravel_index(np.argmax(heatmap), (heatmap.shape[0], heatmap.shape[1]))
x = np.arange(0, size, 1, float)
y = x[:, np.newaxis]
if center is None:
x0 = y0 = size * stride // 2
else:
x0 = center[1]
y0 = center[0]
batch_datum[data_num, :, :, joint_num] = np.exp(
-((x * stride - x0) ** 2 + (y * stride - y0) ** 2) / 2.0 / fwhm / fwhm)
batch_datum[data_num, :, :, heatmaps.shape[3] - 1] = np.ones((size, size)) - np.amax(
batch_datum[data_num, :, :, 0:heatmaps.shape[3] - 1], axis=2)
return batch_datum
cpm_utils.py 文件源码
python
阅读 34
收藏 0
点赞 0
评论 0
评论列表
文章目录