当前位置: 首页>>代码示例>>Python>>正文


Python torch.acos方法代码示例

本文整理汇总了Python中torch.acos方法的典型用法代码示例。如果您正苦于以下问题:Python torch.acos方法的具体用法?Python torch.acos怎么用?Python torch.acos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在torch的用法示例。


在下文中一共展示了torch.acos方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: forward

# 需要导入模块: import torch [as 别名]
# 或者: from torch import acos [as 别名]
def forward(self, input1):
        self.batchgrid3d = torch.zeros(torch.Size([input1.size(0)]) + self.grid3d.size())

        for i in range(input1.size(0)):
            self.batchgrid3d[i] = self.grid3d

        self.batchgrid3d = Variable(self.batchgrid3d)
        #print(self.batchgrid3d)

        x = torch.sum(torch.mul(self.batchgrid3d, input1[:,:,:,0:4]), 3)
        y = torch.sum(torch.mul(self.batchgrid3d, input1[:,:,:,4:8]), 3)
        z = torch.sum(torch.mul(self.batchgrid3d, input1[:,:,:,8:]), 3)
        #print(x)
        r = torch.sqrt(x**2 + y**2 + z**2) + 1e-5

        #print(r)
        theta = torch.acos(z/r)/(np.pi/2)  - 1
        #phi = torch.atan(y/x)
        phi = torch.atan(y/(x + 1e-5))  + np.pi * x.lt(0).type(torch.FloatTensor) * (y.ge(0).type(torch.FloatTensor) - y.lt(0).type(torch.FloatTensor))
        phi = phi/np.pi


        output = torch.cat([theta,phi], 3)

        return output 
开发者ID:guoruoqian,项目名称:cascade-rcnn_Pytorch,代码行数:27,代码来源:gridgen.py

示例2: batch_mat2angle

# 需要导入模块: import torch [as 别名]
# 或者: from torch import acos [as 别名]
def batch_mat2angle(R):
    """ Calcuate the axis angles (twist) from a batch of rotation matrices

        Ethan Eade's lie group note:
        http://ethaneade.com/lie.pdf equation (17)

        function tested in 'test_geometry.py'

    :input
    :param Rotation matrix Bx3x3 \in \SO3 space
    --------
    :return 
    :param the axis angle B
    """
    R1 = [torch.trace(R[i]) for i in range(R.size()[0])]
    R_trace = torch.stack(R1)
    # clamp if the angle is too large (break small angle assumption)
    # @todo: not sure whether it is absoluately necessary in training. 
    angle = acos( ((R_trace - 1)/2).clamp(-1,1))
    return angle 
开发者ID:lvzhaoyang,项目名称:DeeperInverseCompositionalAlgorithm,代码行数:22,代码来源:geometry.py

示例3: rotation_error

# 需要导入模块: import torch [as 别名]
# 或者: from torch import acos [as 别名]
def rotation_error(self, net_roll, net_pitch, tar_roll, tar_pitch ):

        cx1 = torch.cos(net_roll)
        sx1 = torch.sin(net_roll)
        cy1 = torch.cos(net_pitch)
        sy1 = torch.sin(net_pitch)

        cx2 = torch.cos(tar_roll)
        sx2 = torch.sin(tar_roll)
        cy2 = torch.cos(tar_pitch)
        sy2 = torch.sin(tar_pitch)

        m00 = cy1*cy2 + sy1*sy2
        m11 = cx1*cx2 + cy1*cy2*sx1*sx2 + sx1*sx2*sy1*sy2
        m22 = sx1*sx2 + cx1*cx2*sy1*sy2 + cx1*cx2*cy1*cy2
        self.acos =  ( m00 + m11 + m22 - 1)/2.0 * 0.99999
        return torch.acos(self.acos) 
开发者ID:hku-mars,项目名称:crossgap_il_rl,代码行数:19,代码来源:pid_rajectory_follower.py

示例4: arccos

# 需要导入模块: import torch [as 别名]
# 或者: from torch import acos [as 别名]
def arccos(x, out=None):
    """
    Return the trigonometric arccos, element-wise.

    Parameters
    ----------
    x : ht.DNDarray
        The value for which to compute the trigonometric cosine.
    out : ht.DNDarray or None, optional
        A location in which to store the results. If provided, it must have a broadcastable shape. If not provided
        or set to None, a fresh tensor is allocated.

    Returns
    -------
    arccos : ht.DNDarray
        A tensor of the same shape as x, containing the trigonometric arccos of each element in this tensor.
        Input elements outside [-1., 1.] are returned as nan. If out was provided, arccos is a reference to it.

    Examples
    --------
    >>> ht.arccos(ht.array([-1.,-0., 0.83]))
    tensor([3.1416, 1.5708, 0.5917])
    """
    return local_op(torch.acos, x, out) 
开发者ID:helmholtz-analytics,项目名称:heat,代码行数:26,代码来源:trigonometrics.py

示例5: interpolate_sphere

# 需要导入模块: import torch [as 别名]
# 或者: from torch import acos [as 别名]
def interpolate_sphere(self, z1, z2, t):
        ''' Interpolates on a sphere.

        Args:
            z1 (tensor): start latent code
            z2 (tensor): end latent code
            t (tensor): time steps
        '''
        p = (z1 * z2).sum(dim=-1, keepdim=True)
        p = p / z1.pow(2).sum(dim=-1, keepdim=True).sqrt()
        p = p / z2.pow(2).sum(dim=-1, keepdim=True).sqrt()
        omega = torch.acos(p)
        s1 = torch.sin((1-t)*omega)/torch.sin(omega)
        s2 = torch.sin(t*omega)/torch.sin(omega)
        z = s1 * z1 + s2 * z2

        return z 
开发者ID:autonomousvision,项目名称:occupancy_flow,代码行数:19,代码来源:generation.py

示例6: forward

# 需要导入模块: import torch [as 别名]
# 或者: from torch import acos [as 别名]
def forward(self, input, label):
        # normalize features
        x = F.normalize(input)
        # normalize weights
        W = F.normalize(self.weight)
        # dot product
        logits = F.linear(x, W)
        # add margin
        theta = torch.acos(torch.clamp(logits, -1.0 + 1e-7, 1.0 - 1e-7))
        target_logits = torch.cos(theta + self.m)
        one_hot = torch.zeros_like(logits)
        one_hot.scatter_(1, label.view(-1, 1).long(), 1)
        if self.ls_eps > 0:
            one_hot = (1 - self.ls_eps) * one_hot + self.ls_eps / self.out_features
        output = logits * (1 - one_hot) + target_logits * one_hot
        # feature re-scale
        with torch.no_grad():
            B_avg = torch.where(one_hot < 1, torch.exp(self.s * logits), torch.zeros_like(logits))
            B_avg = torch.sum(B_avg) / input.size(0)
            theta_med = torch.median(theta)
            self.s = torch.log(B_avg) / torch.cos(torch.min(self.theta_zero * torch.ones_like(theta_med), theta_med))
        output *= self.s

        return output 
开发者ID:lyakaap,项目名称:Landmark2019-1st-and-3rd-Place-Solution,代码行数:26,代码来源:metric_learning.py

示例7: ts_ss_

# 需要导入模块: import torch [as 别名]
# 或者: from torch import acos [as 别名]
def ts_ss_(v, eps=1e-15, eps2=1e-4):
    # reusable compute
    v_inner = torch.mm(v, v.t())
    vs = v.norm(dim=-1, keepdim=True)
    vs_dot = vs.mm(vs.t())

    # compute triangle(v)
    v_cos = v_inner / vs_dot
    v_cos = v_cos.clamp(-1. + eps2, 1. - eps2)  # clamp to avoid backprop instability
    theta_ = torch.acos(v_cos) + math.radians(10)
    theta_rad = theta_ * math.pi / 180.
    tri = (vs_dot * torch.sin(theta_rad)) / 2.

    # compute sector(v)
    v_norm = (v ** 2).sum(-1, keepdim=True)
    euc_dist = v_norm + v_norm.t() - 2.0 * v_inner
    euc_dist = torch.sqrt(torch.abs(euc_dist) + eps)  # add epsilon to avoid srt(0.)
    magnitude_diff = (vs - vs.t()).abs()
    sec = math.pi * (euc_dist + magnitude_diff) ** 2 * theta_ / 360.

    return tri * sec 
开发者ID:taki0112,项目名称:Vector_Similarity,代码行数:23,代码来源:tss_ss_vectorized.py

示例8: compute_geodesic_distance_from_two_matrices

# 需要导入模块: import torch [as 别名]
# 或者: from torch import acos [as 别名]
def compute_geodesic_distance_from_two_matrices(m1, m2):
    batch=m1.shape[0]
    m = torch.bmm(m1, m2.transpose(1,2)) #batch*3*3
    
    cos = (  m[:,0,0] + m[:,1,1] + m[:,2,2] - 1 )/2
    cos = torch.min(cos, torch.autograd.Variable(torch.ones(batch).cuda()) )
    cos = torch.max(cos, torch.autograd.Variable(torch.ones(batch).cuda())*-1 )
    
    
    theta = torch.acos(cos)
    
    #theta = torch.min(theta, 2*np.pi - theta)
    
    
    return theta


#matrices batch*3*3
#both matrix are orthogonal rotation matrices
#out theta between 0 to pi batch 
开发者ID:papagina,项目名称:RotationContinuity,代码行数:22,代码来源:tools.py

示例9: compute_geodesic_distance_from_two_matrices

# 需要导入模块: import torch [as 别名]
# 或者: from torch import acos [as 别名]
def compute_geodesic_distance_from_two_matrices(m1, m2):
    batch=m1.shape[0]
    m = torch.bmm(m1, m2.transpose(1,2)) #batch*3*3
    
    cos = (  m[:,0,0] + m[:,1,1] + m[:,2,2] - 1 )/2
    cos = torch.min(cos, torch.autograd.Variable(torch.ones(batch).cuda()) )
    cos = torch.max(cos, torch.autograd.Variable(torch.ones(batch).cuda())*-1 )
    
    
    theta = torch.acos(cos)
    
    #theta = torch.min(theta, 2*np.pi - theta)
    
    
    return theta


#matrices batch*3*3
#both matrix are orthogonal rotation matrices
#out theta between 0 to 180 degree batch 
开发者ID:papagina,项目名称:RotationContinuity,代码行数:22,代码来源:tools.py

示例10: log

# 需要导入模块: import torch [as 别名]
# 或者: from torch import acos [as 别名]
def log(g):
    eps = 1.0e-7
    R = g.view(-1, 3, 3)
    tr = btrace(R)
    c = (tr - 1) / 2
    t = torch.acos(c)
    sc = sinc1(t)
    idx0 = (torch.abs(sc) <= eps)
    idx1 = (torch.abs(sc) > eps)
    sc = sc.view(-1, 1, 1)

    X = torch.zeros_like(R)
    if idx1.any():
        X[idx1] = (R[idx1] - R[idx1].transpose(1, 2)) / (2*sc[idx1])

    if idx0.any():
        # t[idx0] == math.pi
        t2 = t[idx0] ** 2
        A = (R[idx0] + torch.eye(3).type_as(R).unsqueeze(0)) * t2.view(-1, 1, 1) / 2
        aw1 = torch.sqrt(A[:, 0, 0])
        aw2 = torch.sqrt(A[:, 1, 1])
        aw3 = torch.sqrt(A[:, 2, 2])
        sgn_3 = torch.sign(A[:, 0, 2])
        sgn_3[sgn_3 == 0] = 1
        sgn_23 = torch.sign(A[:, 1, 2])
        sgn_23[sgn_23 == 0] = 1
        sgn_2 = sgn_23 * sgn_3
        w1 = aw1
        w2 = aw2 * sgn_2
        w3 = aw3 * sgn_3
        w = torch.stack((w1, w2, w3), dim=-1)
        W = mat(w)
        X[idx0] = W

    x = vec(X.view_as(g))
    return x 
开发者ID:vinits5,项目名称:pointnet-registration-framework,代码行数:38,代码来源:so3.py

示例11: dist

# 需要导入模块: import torch [as 别名]
# 或者: from torch import acos [as 别名]
def dist(self, x: torch.Tensor, y: torch.Tensor, *, keepdim=False) -> torch.Tensor:
        inner = self.inner(x, x, y, keepdim=keepdim).clamp(
            -1 + EPS[x.dtype], 1 - EPS[x.dtype]
        )
        return torch.acos(inner) 
开发者ID:geoopt,项目名称:geoopt,代码行数:7,代码来源:sphere.py

示例12: __call__

# 需要导入模块: import torch [as 别名]
# 或者: from torch import acos [as 别名]
def __call__(self, data):
        (row, col), pos, pseudo = data.edge_index, data.pos, data.edge_attr
        assert pos.dim() == 2 and pos.size(1) == 3

        cart = pos[col] - pos[row]

        rho = torch.norm(cart, p=2, dim=-1).view(-1, 1)

        theta = torch.atan2(cart[..., 1], cart[..., 0]).view(-1, 1)
        theta = theta + (theta < 0).type_as(theta) * (2 * PI)

        phi = torch.acos(cart[..., 2] / rho.view(-1)).view(-1, 1)

        if self.norm:
            rho = rho / (rho.max() if self.max is None else self.max)
            theta = theta / (2 * PI)
            phi = phi / PI

        spher = torch.cat([rho, theta, phi], dim=-1)

        if pseudo is not None and self.cat:
            pseudo = pseudo.view(-1, 1) if pseudo.dim() == 1 else pseudo
            data.edge_attr = torch.cat([pseudo, spher.type_as(pos)], dim=-1)
        else:
            data.edge_attr = spher

        return data 
开发者ID:rusty1s,项目名称:pytorch_geometric,代码行数:29,代码来源:spherical.py


注:本文中的torch.acos方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。