Spaces:
Runtime error
Runtime error
File size: 396 Bytes
ec0fdfd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
from torch.nn import functional as F
def d_clip_loss(x, y, use_cosine=False):
x = F.normalize(x, dim=-1)
y = F.normalize(y, dim=-1)
if use_cosine:
distance = 1 - (x @ y.t()).squeeze()
else:
distance = (x - y).norm(dim=-1).div(2).arcsin().pow(2).mul(2)
return distance
def range_loss(input):
return (input - input.clamp(-1, 1)).pow(2).mean([1, 2, 3])
|