Python Examples of torch.gather - ProgramCreek.com
www.programcreek.com › example › 101236def _get_body(self, x, target): cos_t = torch.gather(x, 1, target.unsqueeze(1)) # cos(theta_yi) if self.easy_margin: cond = torch.relu(cos_t) else: cond_v = cos_t - self.threshold cond = torch.relu(cond_v) cond = cond.bool() # Apex would convert FP16 to FP32 here # cos(theta_yi + m) new_zy = torch.cos(torch.acos(cos_t) + self.m).type(cos_t.dtype) if self.easy_margin: zy_keep = cos_t else: zy_keep = cos_t - self.mm # (cos(theta_yi) - sin(pi - m)*m) new_zy = torch.where(cond, new_zy, zy_keep ...
torch.gather — PyTorch 1.10.1 documentation
pytorch.org › docs › stabletorch.gather input ( Tensor) – the source tensor dim ( int) – the axis along which to index index ( LongTensor) – the indices of elements to gather sparse_grad ( bool, optional) – If True, gradient w.r.t. input will be a sparse tensor. out ( Tensor, optional) – the destination tensor