【发布时间】:2021-08-13 14:56:23
【问题描述】:
我想把范数距离改成余弦距离,帮我把这个函数转换成余弦距离
def feat_prototype_distance(self, feat):
N, C, H, W = feat.shape
feat_proto_distance = -torch.ones((N, self.class_numbers, H, W)).to(feat.device)
for i in range(self.class_numbers):
feat_proto_distance[:, i, :, :] = torch.norm(self.objective_vectors[i].reshape(-1,1,1).expand(-1, H, W) - feat, 2, dim=1)
return feat_proto_distance
这是使用带形状的范数距离的原始函数: self.objective_vectors[i].reshape(-1,1,1).expand(-1, H, W): torch.Size([256, 128, 224]) 壮举:torch.Size([8, 256, 128, 224]) with 8 is batch_size
【问题讨论】:
标签: pytorch torch cosine-similarity