Open yuheyuan opened 2 years ago
def feat_prototype_distance(self, feat):
print("enterehre!")
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(torch.Tensor(self.objective_vectors[i]).reshape(-1,1,1).expand(-1, H, W).to(feat.device) - feat, 2, dim=1,)
print(feat)
print(self.objective_vectors[i].to(feat.device))
# print(self.objective_vectors[i])
feat_proto_distance[:, i, :, :] = torch.norm(self.objective_vectors[i].reshape(-1,1,1).expand(-1, H, W) - feat, 2, dim=1,) # here feat.toGPU, but self.objective_vecotrs belong to cpu
return feat_proto_distance
I find it may be occur torch.norm here,one belong to GPU, one belong to CPU
when I run tran.py
I only want to use two gpu, So I change the code only in here