, когда я пытаюсь обучить свою модель,
"ValueError: Type must be a sub-type of ndarray type"
возникает в line x_norm=(np.power(x,2)).sum(1).view(-1,1)
.
Код:
def pairwise_distances(x, y=None):
x_norm = (np.power(x,2)).sum(1).view(-1, 1)
if y is not None:
y_t = torch.transpose(y, 0, 1)
y_norm = (y**2).sum(1).view(1, -1)
else:
y_t = torch.transpose(x, 0, 1)
y_norm = x_norm.view(1, -1)
dist = x_norm + y_norm - 2.0 * torch.mm(x, y_t)
# Ensure diagonal is zero if x=y
# if y is None:
# dist = dist - torch.diag(dist.diag)
return torch.clamp(dist, 0.0, np.inf)