num_fea = ['price','v_0', 'v_1', 'v_2', 'v_3','v_4', 'v_5', 'v_6', 'v_7', 'v_8', 'v_9', 'v_10', 'v_11', 'v_12','v_13', 'v_14'] plt.figure(figsize=(8, 6)) sns.heatmap(df_train_new[num_fea].corr(), linewidths=0.1, cmap=sns.cm.rocket_r) plt.show()
时间: 2023-03-31 12:02:42 浏览: 122
这是一个数据分析的问题,我可以回答。这段代码是用于绘制热力图,展示数据集中数值型特征之间的相关性。其中,num_fea是数值型特征的列表,plt.figure()是设置图像的大小,sns.heatmap()是绘制热力图,linewidths是设置每个格子之间的间隔,cmap是设置颜色映射。最后,plt.show()是显示图像。
相关问题
def build_gwc_volume_cos(refimg_fea, targetimg_fea, maxdisp, num_groups): refimg_fea = refimg_fea/(torch.sum(refimg_fea**2, dim=1,keepdim=True).pow(1/2)+1e-05) targetimg_fea = targetimg_fea/(torch.sum(targetimg_fea**2, dim=1,keepdim=True).pow(1/2)+1e-05) B, C, H, W = refimg_fea.shape volume = refimg_fea.new_zeros([B, num_groups, maxdisp, H, W]) for i in range(maxdisp): if i > 0: volume[:, :, i, :, i:] = groupwise_correlation(refimg_fea[:, :, :, i:], targetimg_fea[:, :, :, :-i], num_groups) else: volume[:, :, i, :, :] = groupwise_correlation(refimg_fea, targetimg_fea, num_groups) volume = volume.contiguous() return volume
这是一个构建视差体积的函数,输入参数包括参考图像特征(refimg_fea)、目标图像特征(targetimg_fea)、最大视差(maxdisp)和分组数(num_groups)。首先,对参考图像特征和目标图像特征进行归一化处理。然后,根据最大视差和分组数创建一个大小为[B, num_groups, maxdisp, H, W]的零张量(volume)。接下来,通过循环遍历每个视差值i,计算对应视差的分组相关性并将结果存储在volume张量中。最后,返回计算完成的volume张量。
修改下列模块代码,使其能够对三维模型的直线特征进行提取:class FaceKernelCorrelation(nn.Module): def __init__(self, num_kernel=64, sigma=0.2): super(FaceKernelCorrelation, self).__init__() self.num_kernel = num_kernel self.sigma = sigma self.weight_alpha = Parameter(torch.rand(1, num_kernel, 4) * np.pi) self.weight_beta = Parameter(torch.rand(1, num_kernel, 4) * 2 * np.pi) self.bn = nn.BatchNorm1d(num_kernel) self.relu = nn.ReLU() def forward(self, normals, neighbor_index): b, _, n = normals.size() center = normals.unsqueeze(2).expand(-1, -1, self.num_kernel, -1).unsqueeze(4) neighbor = torch.gather(normals.unsqueeze(3).expand(-1, -1, -1, 3), 2, neighbor_index.unsqueeze(1).expand(-1, 3, -1, -1)) neighbor = neighbor.unsqueeze(2).expand(-1, -1, self.num_kernel, -1, -1) fea = torch.cat([center, neighbor], 4) fea = fea.unsqueeze(5).expand(-1, -1, -1, -1, -1, 4) weight = torch.cat([torch.sin(self.weight_alpha) * torch.cos(self.weight_beta), torch.sin(self.weight_alpha) * torch.sin(self.weight_beta), torch.cos(self.weight_alpha)], 0) weight = weight.unsqueeze(0).expand(b, -1, -1, -1) weight = weight.unsqueeze(3).expand(-1, -1, -1, n, -1) weight = weight.unsqueeze(4).expand(-1, -1, -1, -1, 4, -1) dist = torch.sum((fea - weight)**2, 1) fea = torch.sum(torch.sum(np.e**(dist / (-2 * self.sigma**2)), 4), 3) / 16 return self.relu(self.bn(fea))
修改后的代码如下:
```python
class FaceKernelCorrelation(nn.Module):
def __init__(self, num_kernel=64, sigma=0.2):
super(FaceKernelCorrelation, self).__init__()
self.num_kernel = num_kernel
self.sigma = sigma
self.weight_alpha = Parameter(torch.rand(1, num_kernel, 6) * np.pi)
self.weight_beta = Parameter(torch.rand(1, num_kernel, 6) * 2 * np.pi)
self.bn = nn.BatchNorm1d(num_kernel)
self.relu = nn.ReLU()
def forward(self, vertices, neighbor_index):
b, _, n = vertices.size()
center = vertices.unsqueeze(2).expand(-1, -1, self.num_kernel, -1).unsqueeze(4)
neighbor = torch.gather(vertices.unsqueeze(3).expand(-1, -1, -1, 3),
2, neighbor_index.unsqueeze(1).expand(-1, 3, -1, -1))
neighbor = neighbor.unsqueeze(2).expand(-1, -1, self.num_kernel, -1, -1)
# 计算直线特征
line = neighbor - center
length = torch.sqrt(torch.sum(line**2, dim=-1, keepdim=True))
direction = line / (length + 1e-8)
fea = torch.cat([center, direction, length], dim=4)
fea = fea.unsqueeze(5).expand(-1, -1, -1, -1, -1, 6)
weight = torch.cat([torch.sin(self.weight_alpha) * torch.cos(self.weight_beta),
torch.sin(self.weight_alpha) * torch.sin(self.weight_beta),
torch.cos(self.weight_alpha)], 0)
weight = weight.unsqueeze(0).expand(b, -1, -1, -1)
weight = weight.unsqueeze(3).expand(-1, -1, -1, n, -1)
weight = weight.unsqueeze(4).expand(-1, -1, -1, -1, 6, -1)
dist = torch.sum((fea - weight)**2, 1)
fea = torch.sum(torch.sum(np.e**(dist / (-2 * self.sigma**2)), 4), 3) / 16
return self.relu(self.bn(fea))
```
对比原有的代码,主要修改的地方如下:
1. 修改了 weight_alpha 和 weight_beta 的形状,将其从 4 改为 6,以便存储直线特征;
2. 在 forward 函数中,首先计算出所有点的邻居点,然后根据邻居点和中心点计算出直线特征(即方向向量和长度),并将其拼接在一起;
3. 将拼接后的直线特征与权重相减后,进行距离计算和高斯加权求和。
阅读全文