當前位置: 首頁>>代碼示例>>Python>>正文


Python torch.DoubleTensor方法代碼示例

本文整理匯總了Python中torch.DoubleTensor方法的典型用法代碼示例。如果您正苦於以下問題:Python torch.DoubleTensor方法的具體用法?Python torch.DoubleTensor怎麽用?Python torch.DoubleTensor使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在torch的用法示例。


在下文中一共展示了torch.DoubleTensor方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_dbbox2delta

# 需要導入模塊: import torch [as 別名]
# 或者: from torch import DoubleTensor [as 別名]
def test_dbbox2delta(self):
        """
        encoding format similar to RRPN, except the angle was restricted to [0, 2 pi], dangle was restricted to [0, 1]

        Must Test corner cases
        :return:
        """
        boxlist1 = torch.DoubleTensor([[1, 1, 10, 5, 0],
                                  [1, 1, 10, 5, np.pi/10],
                                  [1, 1, 10, 5, 0],
                                  [30, 100, 60, 34, np.pi/2]
                                  ])

        boxlist2 = torch.DoubleTensor([[1, 1, 5, 8, np.pi/16],
                                  [1, 1, 5, 8, np.pi/16 + np.pi/10],
                                  [1, 1, 10, 5, 0],
                                  [30, 90, 12, 45, np.pi/10]
                                  ])
        expected_targets = torch.DoubleTensor([[0.0000,  0.0000, -0.6931,  0.4700,  0.0312],
                                        [0.0000,  0.0000, -0.6931,  0.4700,  0.0313],
                                        [0.0000,  0.0000,  0.0000,  0.0000,  0.0000],
                                        [-0.1667,  0.0000, -1.6094,  0.2803, 0.8]])

        output = dbbox2delta(boxlist1, boxlist2)
        np.testing.assert_almost_equal(expected_targets.numpy(), output.numpy(), decimal=4) 
開發者ID:dingjiansw101,項目名稱:AerialDetection,代碼行數:27,代碼來源:transforms_rbbox_test.py

示例2: test_dbbox_flip

# 需要導入模塊: import torch [as 別名]
# 或者: from torch import DoubleTensor [as 別名]
def test_dbbox_flip(self):
        """

        :return:
        """
        dbboxes = torch.DoubleTensor([[50, 60, 50, 30, np.pi/3, 23.5, 60, 50, 30, np.pi/3 + np.pi/10],
                                      [30, 20, 30, 30, np.pi/6, 10.33, 20, 30, 30, np.pi/6 - np.pi/11]])
        img_shape = (1024, 1024)

        expected_targets = torch.DoubleTensor([[973, 60, 50, 30, np.pi/3*2, 999.5, 60, 50, 30, np.pi*17/30],
                                               [993, 20, 30, 30, np.pi/6*5, 1012.67, 20, 30, 30, np.pi*61/66]])

        output = dbbox_flip(dbboxes, img_shape)

        np.testing.assert_almost_equal(expected_targets.numpy(), output.numpy(), decimal=6)

    # def dbbox_mapping(self):
    #
    #     dbboxes = torch.DoubleTensor([[50, 60, 50, 30, np.pi/3, 23.5, 60, 50, 30, np.pi/3 + np.pi/10],
    #                                   [30, 20, 30, 30, np.pi/6, 10.33, 20, 30, 30, np.pi/6 - np.pi/11]])
    #     img_shape 
開發者ID:dingjiansw101,項目名稱:AerialDetection,代碼行數:23,代碼來源:transforms_rbbox_test.py

示例3: test_dbbox2roi

# 需要導入模塊: import torch [as 別名]
# 或者: from torch import DoubleTensor [as 別名]
def test_dbbox2roi(self):

        dbbox_list = [torch.DoubleTensor([[2, 3, 39, 30, np.pi/2],
                                          [3.2, 3, 30, 20, np.pi/3]]),
                      torch.DoubleTensor([[1, 3, 39, 30, np.pi / 2],
                                          [5.2, 3, 30, 20, np.pi / 3]]) ]

        expected_targets = np.array([[0, 2, 3, 39, 30, np.pi/2],
                                     [0, 3.2, 3, 30, 20, np.pi/3],
                                     [1, 1, 3, 39, 30, np.pi / 2],
                                     [1, 5.2, 3, 30, 20, np.pi / 3]
                                     ])

        outputs = dbbox2roi(dbbox_list)

        np.testing.assert_almost_equal(expected_targets, outputs.numpy()) 
開發者ID:dingjiansw101,項目名稱:AerialDetection,代碼行數:18,代碼來源:transforms_rbbox_test.py

示例4: test_droi2dbbox

# 需要導入模塊: import torch [as 別名]
# 或者: from torch import DoubleTensor [as 別名]
def test_droi2dbbox(self):

        drois = np.array([[0, 2, 3, 39, 30, np.pi/2],
                                     [0, 3.2, 3, 30, 20, np.pi/3],
                                     [1, 1, 3, 39, 30, np.pi / 2],
                                     [1, 5.2, 3, 30, 20, np.pi / 3]
                                     ])
        drois = torch.from_numpy(drois)

        outputs = droi2dbbox(drois)

        expected_targets = [torch.DoubleTensor([[2, 3, 39, 30, np.pi/2],
                                          [3.2, 3, 30, 20, np.pi/3]]),
                      torch.DoubleTensor([[1, 3, 39, 30, np.pi / 2],
                                          [5.2, 3, 30, 20, np.pi / 3]])]
        np.testing.assert_equal(len(outputs), 2)
        np.testing.assert_equal(expected_targets[0].shape == outputs[0].shape, True)
        np.testing.assert_equal(expected_targets[1].shape == outputs[1].shape, True)

        # np.testing.assert_almost_equal(expected_targets, outputs.numpy()) 
開發者ID:dingjiansw101,項目名稱:AerialDetection,代碼行數:22,代碼來源:transforms_rbbox_test.py

示例5: pixelwise_accuracy

# 需要導入模塊: import torch [as 別名]
# 或者: from torch import DoubleTensor [as 別名]
def pixelwise_accuracy(num_classes, output_transform=lambda x: x, device=None):
    """Calculates class accuracy

    Args:
        num_classes (int): number of classes
        output_transform (callable, optional): a callable that is used to transform the
            output into the form expected by the metric.

    Returns:
        MetricsLambda

    """
    cm = ignite.metrics.ConfusionMatrix(num_classes=num_classes, output_transform=output_transform, device=device)
    # Increase floating point precision and pass to CPU
    cm = cm.type(torch.DoubleTensor)

    pix_cls = ignite.metrics.confusion_matrix.cmAccuracy(cm)

    return pix_cls 
開發者ID:microsoft,項目名稱:seismic-deeplearning,代碼行數:21,代碼來源:metrics.py

示例6: class_accuracy

# 需要導入模塊: import torch [as 別名]
# 或者: from torch import DoubleTensor [as 別名]
def class_accuracy(num_classes, output_transform=lambda x: x, device=None):
    """Calculates class accuracy

    Args:
        num_classes (int): number of classes
        output_transform (callable, optional): a callable that is used to transform the
            output into the form expected by the metric.

    Returns:
        MetricsLambda

    """
    cm = ignite.metrics.ConfusionMatrix(num_classes=num_classes, output_transform=output_transform, device=device)
    # Increase floating point precision and pass to CPU
    cm = cm.type(torch.DoubleTensor)

    acc_cls = cm.diag() / (cm.sum(dim=1) + 1e-15)

    return acc_cls 
開發者ID:microsoft,項目名稱:seismic-deeplearning,代碼行數:21,代碼來源:metrics.py

示例7: test_horovod_allreduce_grad_average

# 需要導入模塊: import torch [as 別名]
# 或者: from torch import DoubleTensor [as 別名]
def test_horovod_allreduce_grad_average(self):
        """Test the correctness of the allreduce averaged gradient."""
        hvd.init()
        dtypes = [torch.IntTensor, torch.LongTensor,
                  torch.FloatTensor, torch.DoubleTensor]
        if torch.cuda.is_available():
            dtypes += [torch.cuda.IntTensor, torch.cuda.LongTensor,
                       torch.cuda.FloatTensor, torch.cuda.DoubleTensor]
        dims = [1, 2, 3]
        for dtype, dim in itertools.product(dtypes, dims):
            torch.manual_seed(1234)
            tensor = torch.FloatTensor(*([17] * dim)).random_(-100, 100)
            tensor = tensor.type(dtype)
            tensor = torch.autograd.Variable(tensor, requires_grad=True)
            summed = hvd.allreduce(tensor, average=True)

            summed.backward(torch.ones([17] * dim))
            grad_out = tensor.grad.data.numpy()

            expected = np.ones([17] * dim)
            err = np.linalg.norm(expected - grad_out)
            self.assertLess(err, 0.00000001,
                            "gradient %s differs from expected %s, "
                            "error: %s" % (grad_out, expected, str(err))) 
開發者ID:mlperf,項目名稱:training_results_v0.6,代碼行數:26,代碼來源:test_torch.py

示例8: test_sum_metric_inputs

# 需要導入模塊: import torch [as 別名]
# 或者: from torch import DoubleTensor [as 別名]
def test_sum_metric_inputs(self):

        passing_inputs_and_outputs = [
            (2, 2.0),
            (-5.0, -5.0),
            (torch.LongTensor([[-1]]), -1.0),
            (torch.DoubleTensor([34.68]), 34.68),
        ]
        for input_, output in passing_inputs_and_outputs:
            actual_output = SumMetric(input_).value()
            self.assertEqual(actual_output, output)

        failing_inputs = [
            ('4', AssertionError),
            ([6.8], AssertionError),
            (torch.Tensor([1, 3.8]), ValueError),  # Tensor has more than 1 element
        ]
        for input_, error in failing_inputs:
            with self.assertRaises(error):
                SumMetric(input_) 
開發者ID:facebookresearch,項目名稱:ParlAI,代碼行數:22,代碼來源:test_metrics.py

示例9: calc_relative_scale

# 需要導入模塊: import torch [as 別名]
# 或者: from torch import DoubleTensor [as 別名]
def calc_relative_scale(skeleton, ref_bone_lengths, joint_tree) -> (float, float):
    """Calculate the factor by which the reference is larger than the query skeleton.

    Args:
        skeleton (torch.DoubleTensor): The query skeleton.
        ref_bone_lengths (torch.DoubleTensor): The reference skeleton bone lengths.
        joint_tree (list of int):

    Returns:
        The average scale factor.
    """

    bone_lengths = cartesian_to_spherical(
        absolute_to_parent_relative(ensure_cartesian(skeleton, d=3), joint_tree)
    )[:, 0]

    non_zero = bone_lengths.gt(1e-6)
    if non_zero.sum() == 0: return 0
    ratio = (ref_bone_lengths / bone_lengths).masked_select(non_zero)

    return ratio.median().item() 
開發者ID:anibali,項目名稱:margipose,代碼行數:23,代碼來源:skeleton.py

示例10: convert_one_hot

# 需要導入模塊: import torch [as 別名]
# 或者: from torch import DoubleTensor [as 別名]
def convert_one_hot(self, labels):
        """
        Converts a list of grasp angle labels to a Torch tensor of one_hot labels
    
        :param labels: List of angle labels
        :type labels: list
    
        :returns: A torch tensor of one_hot labels
        :rtype: torch Tensor
        """
        batch_size = len(labels)
        labels_tensor = Variable(torch.LongTensor(labels))
        y_onehot = Variable(torch.DoubleTensor(batch_size, n_class))
        y_onehot.zero_()
        labels_onehot = y_onehot.scatter_(1, labels_tensor.view(-1, 1), 1)
        return labels_onehot 
開發者ID:facebookresearch,項目名稱:pyrobot,代碼行數:18,代碼來源:grasp_object.py

示例11: convert_robot_one_hot

# 需要導入模塊: import torch [as 別名]
# 或者: from torch import DoubleTensor [as 別名]
def convert_robot_one_hot(self, labels):
        """
        Converts a list of robot_id labels to a Torch tensor of one_hot labels
    
        :param labels: List of robot_id labels
        :type labels: list
    
        :returns: A torch tensor of one_hot labels
        :rtype: torch Tensor
        """
        batch_size = len(labels)
        labels_tensor = Variable(torch.LongTensor(labels))
        y_onehot = Variable(torch.DoubleTensor(batch_size, n_rob))
        y_onehot.zero_()
        labels_onehot = y_onehot.scatter_(1, labels_tensor.view(-1, 1), 1)
        return labels_onehot 
開發者ID:facebookresearch,項目名稱:pyrobot,代碼行數:18,代碼來源:grasp_object.py

示例12: __init__

# 需要導入模塊: import torch [as 別名]
# 或者: from torch import DoubleTensor [as 別名]
def __init__(self, n, Qpenalty, qp_solver, trueInit=False):
        super().__init__()

        self.qp_solver = qp_solver

        nx = (n**2)**3
        self.Q = Variable(Qpenalty*torch.eye(nx).double().cuda())
        self.Q_idx = spa.csc_matrix(self.Q.detach().cpu().numpy()).nonzero()

        self.G = Variable(-torch.eye(nx).double().cuda())
        self.h = Variable(torch.zeros(nx).double().cuda())
        t = get_sudoku_matrix(n)

        if trueInit:
            self.A = Parameter(torch.DoubleTensor(t).cuda())
        else:
            self.A = Parameter(torch.rand(t.shape).double().cuda())
        self.log_z0 = Parameter(torch.zeros(nx).double().cuda())
        # self.b = Variable(torch.ones(self.A.size(0)).double().cuda())

        if self.qp_solver == 'osqpth':
            t = torch.cat((self.A, self.G), dim=0)
            self.AG_idx = spa.csc_matrix(t.detach().cpu().numpy()).nonzero()

    # @profile 
開發者ID:locuslab,項目名稱:optnet,代碼行數:27,代碼來源:models.py

示例13: test_nms_device_and_dtypes_cpu

# 需要導入模塊: import torch [as 別名]
# 或者: from torch import DoubleTensor [as 別名]
def test_nms_device_and_dtypes_cpu():
    """
    CommandLine:
        xdoctest -m tests/test_nms.py test_nms_device_and_dtypes_cpu
    """
    iou_thr = 0.6
    base_dets = np.array([[49.1, 32.4, 51.0, 35.9, 0.1],
                          [49.3, 32.9, 51.0, 35.3, 0.05],
                          [35.3, 11.5, 39.9, 14.5, 0.9],
                          [35.2, 11.7, 39.7, 15.7, 0.3]])

    base_expected_suppressed = np.array([[35.3, 11.5, 39.9, 14.5, 0.9],
                                         [49.1, 32.4, 51.0, 35.9, 0.1]])
    # CPU can handle float32 and float64
    dets = base_dets.astype(np.float32)
    expected_suppressed = base_expected_suppressed.astype(np.float32)
    suppressed, inds = nms(dets, iou_thr)
    assert dets.dtype == suppressed.dtype
    assert np.array_equal(suppressed, expected_suppressed)

    dets = torch.FloatTensor(base_dets)
    expected_suppressed = torch.FloatTensor(base_expected_suppressed)
    suppressed, inds = nms(dets, iou_thr)
    assert dets.dtype == suppressed.dtype
    assert torch.equal(suppressed, expected_suppressed)

    dets = base_dets.astype(np.float64)
    expected_suppressed = base_expected_suppressed.astype(np.float64)
    suppressed, inds = nms(dets, iou_thr)
    assert dets.dtype == suppressed.dtype
    assert np.array_equal(suppressed, expected_suppressed)

    dets = torch.DoubleTensor(base_dets)
    expected_suppressed = torch.DoubleTensor(base_expected_suppressed)
    suppressed, inds = nms(dets, iou_thr)
    assert dets.dtype == suppressed.dtype
    assert torch.equal(suppressed, expected_suppressed) 
開發者ID:open-mmlab,項目名稱:mmdetection,代碼行數:39,代碼來源:test_nms.py

示例14: test_soft_nms_device_and_dtypes_cpu

# 需要導入模塊: import torch [as 別名]
# 或者: from torch import DoubleTensor [as 別名]
def test_soft_nms_device_and_dtypes_cpu():
    """
    CommandLine:
        xdoctest -m tests/test_soft_nms.py test_soft_nms_device_and_dtypes_cpu
    """
    iou_thr = 0.7
    base_dets = np.array([[49.1, 32.4, 51.0, 35.9, 0.9],
                          [49.3, 32.9, 51.0, 35.3, 0.9],
                          [35.3, 11.5, 39.9, 14.5, 0.4],
                          [35.2, 11.7, 39.7, 15.7, 0.3]])

    # CPU can handle float32 and float64
    dets = base_dets.astype(np.float32)
    new_dets, inds = soft_nms(dets, iou_thr)
    assert dets.dtype == new_dets.dtype
    assert len(inds) == len(new_dets) == 4

    dets = torch.FloatTensor(base_dets)
    new_dets, inds = soft_nms(dets, iou_thr)
    assert dets.dtype == new_dets.dtype
    assert len(inds) == len(new_dets) == 4

    dets = base_dets.astype(np.float64)
    new_dets, inds = soft_nms(dets, iou_thr)
    assert dets.dtype == new_dets.dtype
    assert len(inds) == len(new_dets) == 4

    dets = torch.DoubleTensor(base_dets)
    new_dets, inds = soft_nms(dets, iou_thr)
    assert dets.dtype == new_dets.dtype
    assert len(inds) == len(new_dets) == 4 
開發者ID:open-mmlab,項目名稱:mmdetection,代碼行數:33,代碼來源:test_soft_nms.py

示例15: test_xy2wh

# 需要導入模塊: import torch [as 別名]
# 或者: from torch import DoubleTensor [as 別名]
def test_xy2wh(self):

        boxes = torch.DoubleTensor([[1, 3, 45, 10],
                          [24.4, 3., 44.5, 52.2]])
        outputs = xy2wh(boxes)
        expected_outputs = np.array([[23, 6.5, 45, 8],
                                     [34.45, 27.6, 21.1, 50.2]])
        np.testing.assert_almost_equal(expected_outputs, outputs.numpy()) 
開發者ID:dingjiansw101,項目名稱:AerialDetection,代碼行數:10,代碼來源:transforms_rbbox_test.py


注:本文中的torch.DoubleTensor方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。