예제 #1
0
def test_conv2d_mpc_mpc(get_clients, nr_clients, bias, stride,
                        padding) -> None:
    clients = get_clients(nr_clients)
    session = Session(parties=clients)
    SessionManager.setup_mpc(session)

    input_secret = torch.ones(1, 1, 4, 4)
    weight_secret = torch.ones(1, 1, 2, 2)
    input = MPCTensor(secret=input_secret, session=session)
    weight = MPCTensor(secret=weight_secret, session=session)

    kwargs = {"bias": bias, "stride": stride, "padding": padding}

    result = input.conv2d(weight, **kwargs).reconstruct()
    expected_result = torch.nn.functional.conv2d(input_secret, weight_secret,
                                                 **kwargs)

    assert np.allclose(result, expected_result, rtol=10e-4)
예제 #2
0
    def forward(self, x: MPCTensor) -> MPCTensor:
        """Do a feedforward through the layer.

        Args:
            x (MPCTensor): the input

        Returns:
            An MPCTensor representing the layer specific operation applied on the input
        """
        res = x.conv2d(
            weight=self.weight,
            bias=self.bias,
            stride=self.stride,
            padding=self.padding,
            dilation=self.dilation,
            groups=self.groups,
        )

        return res