def gen_label_heatmap(self, label): label = torch.Tensor(label) grid = torch.zeros((self.label_size, self.label_size, 2)) # size:(46,46,2) grid[..., 0] = torch.Tensor(range(self.label_size)).unsqueeze(0) grid[..., 1] = torch.Tensor(range(self.label_size)).unsqueeze(1) grid = grid.unsqueeze(0) labels = label.unsqueeze(-2).unsqueeze(-2) exponent = torch.sum((grid - labels)**2, dim=-1) # size:(21,46,46) heatmaps = torch.exp(-exponent / 2.0 / self.sigma / self.sigma) return heatmaps
时间: 2023-05-29 20:06:45 浏览: 152
百度地图api绘制热力图以及Label和Echarts组合对marker进行自定义提示.zip
这段代码的功能是生成一个标签热力图,输入参数为标签。首先将标签转换成PyTorch张量格式,然后创建一个尺寸为self.label_size x self.label_size x 2的全零张量作为网格。
阅读全文