Normalizing to unit length along the specified dimension. Args: x: pytorch Variable Returns: x: pytorch Variable, same shape as input
(x, axis=-1)
| 16 | |
| 17 | |
| 18 | def normalize(x, axis=-1): |
| 19 | """Normalizing to unit length along the specified dimension. |
| 20 | Args: |
| 21 | x: pytorch Variable |
| 22 | Returns: |
| 23 | x: pytorch Variable, same shape as input |
| 24 | """ |
| 25 | x = 1. * x / (torch.norm(x, 2, axis, keepdim=True).expand_as(x) + 1e-12) |
| 26 | return x |
| 27 | |
| 28 | |
| 29 | class TripletLoss_WRT(nn.Module): |