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


Python Variable.send方法代码示例

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


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

示例1: test_torch_function_with_multiple_output_on_remote_var

# 需要导入模块: from torch.autograd import Variable [as 别名]
# 或者: from torch.autograd.Variable import send [as 别名]
    def test_torch_function_with_multiple_output_on_remote_var(self):
        hook = TorchHook(verbose=False)
        me = hook.local_worker
        remote = VirtualWorker(id=2, hook=hook)
        me.add_worker(remote)

        x = Var(torch.FloatTensor([[1, 2], [4, 3], [5, 6]]))
        x.send(remote)
        y, z = torch.max(x, 1)
        y.get()
        assert torch.equal(y, Var(torch.FloatTensor([2, 4, 6])))

        x = Var(torch.FloatTensor([[0, 0], [1, 0]])).send(remote)
        y, z = torch.qr(x)
        assert (y.get() == Var(torch.FloatTensor([[0, -1], [-1, 0]]))).all()
        assert (z.get() == Var(torch.FloatTensor([[-1, 0], [0, 0]]))).all()

        x = Var(torch.arange(1, 6)).send(remote)
        y, z = torch.kthvalue(x, 4)
        assert (y.get() == Var(torch.FloatTensor([4]))).all()
        assert (z.get() == Var(torch.LongTensor([3]))).all()

        x = Var(torch.FloatTensor([[0, 0], [0, 0]]))
        x.send(remote)
        y, z = torch.eig(x, True)
        assert (y.get() == Var(torch.FloatTensor([[0, 0], [0, 0]]))).all()
        assert (z.get() == Var(torch.FloatTensor([[1, 0.], [0, 1]]))).all()


        x = Var(torch.zeros(3, 3)).send(remote)
        w, y, z = torch.svd(x)
        assert (w.get() == Var(torch.FloatTensor([[1, 0, 0], [0, 1, 0], [0, 0, 1]]))).all()
        assert (y.get() == Var(torch.FloatTensor([0, 0, 0]))).all()
        assert (z.get() == Var(torch.FloatTensor([[1, 0, 0], [0, 1, 0], [0, 0, 1]]))).all()
开发者ID:TanayGahlot,项目名称:PySyft,代码行数:36,代码来源:torch_test.py

示例2: test_encode_decode_json_python

# 需要导入模块: from torch.autograd import Variable [as 别名]
# 或者: from torch.autograd.Variable import send [as 别名]
    def test_encode_decode_json_python(self):
        """
            Test that the python objects are correctly encoded and decoded in
            json with our encoder/JSONDecoder.
            The main focus is on non-serializable objects, such as torch Variable
            or tuple, or even slice().
        """
        hook = TorchHook(verbose=False)
        local = hook.local_worker
        remote = VirtualWorker(id=1, hook=hook)
        local.add_worker(remote)

        encoder = utils.PythonEncoder(retrieve_tensorvar=True)
        decoder = utils.PythonJSONDecoder(remote)
        x = Var(torch.FloatTensor([[1, -1],[0,1]]))
        x.send(remote)
        # Note that there is two steps of encoding/decoding because the first
        # transforms `Variable containing:[torch.FloatTensor - Locations:[
        # <syft.core.workers.virtual.VirtualWorker id:2>]]` into
        # Variable containing:[torch.FloatTensor - Locations:[2]]`
        obj = [None, ({'marcel': (1, [1.3], x), 'proust': slice(0, 2, None)}, 3)]
        enc, t = encoder.encode(obj)
        enc = json.dumps(enc)
        dec1 = decoder.decode(enc)
        enc, t = encoder.encode(dec1)
        enc = json.dumps(enc)
        dec2 = decoder.decode(enc)
        assert dec1 == dec2
开发者ID:TanayGahlot,项目名称:PySyft,代码行数:30,代码来源:torch_test.py

示例3: test_torch_F_relu_on_remote_var

# 需要导入模块: from torch.autograd import Variable [as 别名]
# 或者: from torch.autograd.Variable import send [as 别名]
    def test_torch_F_relu_on_remote_var(self):
        hook = TorchHook(verbose=False)
        me = hook.local_worker
        remote = VirtualWorker(id=2,hook=hook)
        me.add_worker(remote)

        x = Var(torch.FloatTensor([[1, -1], [-1, 1]]))
        x.send(remote)
        x = F.relu(x)
        x.get()
        assert torch.equal(x, Var(torch.FloatTensor([[1, 0], [0, 1]])))
开发者ID:TanayGahlot,项目名称:PySyft,代码行数:13,代码来源:torch_test.py

示例4: test_torch_nn_conv2d_on_remote_var

# 需要导入模块: from torch.autograd import Variable [as 别名]
# 或者: from torch.autograd.Variable import send [as 别名]
    def test_torch_nn_conv2d_on_remote_var(self):
        hook = TorchHook(verbose=False)
        me = hook.local_worker
        remote = VirtualWorker(id=2,hook=hook)
        me.add_worker(remote)

        x = Var(torch.FloatTensor([[[[1, -1, 2], [-1, 0, 1], [1, 0, -2]]]]))
        x.send(remote)
        convolute = nn.Conv2d(1, 1, 2, stride=1, padding=0)
        convolute.weight = torch.nn.Parameter(torch.FloatTensor([[[[1, -1], [-1, 1]]]]))
        convolute.bias = torch.nn.Parameter(torch.FloatTensor([0]))
        convolute.send(remote)
        conv = convolute(x)
        conv.get()
        expected_conv = Var(torch.FloatTensor([[[[3, -2], [-2, -3]]]]))
        assert torch.equal(conv, expected_conv)
开发者ID:TanayGahlot,项目名称:PySyft,代码行数:18,代码来源:torch_test.py

示例5: test_torch_F_conv2d_on_remote_var

# 需要导入模块: from torch.autograd import Variable [as 别名]
# 或者: from torch.autograd.Variable import send [as 别名]
    def test_torch_F_conv2d_on_remote_var(self):
        hook = TorchHook(verbose=False)
        me = hook.local_worker
        remote = VirtualWorker(id=2,hook=hook)
        me.add_worker(remote)

        x = Var(torch.FloatTensor([[[[1, -1, 2], [-1, 0, 1], [1, 0, -2]]]]))
        x.send(remote)
        weight = torch.nn.Parameter(torch.FloatTensor([[[[1, -1], [-1, 1]]]]))
        bias = torch.nn.Parameter(torch.FloatTensor([0]))
        weight.send(remote)
        bias.send(remote)
        conv = F.conv2d(x, weight, bias, stride=(1,1))
        conv.get()
        expected_conv = Var(torch.FloatTensor([[[[3, -2], [-2, -3]]]]))
        assert torch.equal(conv, expected_conv)
开发者ID:TanayGahlot,项目名称:PySyft,代码行数:18,代码来源:torch_test.py


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