コード例 #1
0
def test_bilinear_interpolation_cpu():

    # Basic MappedConvolution layer
    layer = MappedConvolution(in_channels=in_channels,
                              out_channels=out_channels,
                              kernel_size=kernel_size).double()

    # Run a forward and backward pass
    output, forward_time, backward_time, gradcheck_res = utils.mapped_conv_test(
        layer,
        weight=params.weights_unit(in_channels, out_channels),
        input=params.input_4x5().repeat(bs, in_channels, 1, 1),
        sample_map=params.sample_map1(),
        cuda=False)

    # Manually computed correct result
    correct_output = 2 + params.in_channels * torch.tensor(
        [[35.75, 16.00, 28.00, 39.25, 45.00], [
            32.25, 32.00, 23.00, 36.75, 29.00
        ], [34.50, 47.00, 31.00, 34.25, 33.75],
         [39.00, 27.00, 35.25, 40.75, 39.50]]).double()

    # Assert gradient check has passed
    assert gradcheck_res

    # Assert outputs match
    testing.assert_allclose(output, correct_output)
コード例 #2
0
def test_max_pool_bilinear_interpolation_sampling_cpu():

    # Basic MappedTransposedConvolution layer
    layer = MappedMaxPool(kernel_size=kernel_size).double()

    # Run a forward and backward pass
    output, forward_time, backward_time, gradcheck_res = utils.mapped_pool_test(
        layer,
        input=params.input_4x5().repeat(bs, 1, 1, 1),
        sample_map=params.sample_map1(),
        cuda=False)

    # Manually computed correct result
    correct_output = torch.tensor([[14, 5, 8.25, 13, 16],
                                   [9.25, 9, 9.25, 13,
                                    13], [13, 15, 15, 13, 11],
                                   [13, 13, 13, 13, 15]]).double()

    # Assert gradient check has passed
    assert gradcheck_res

    # Assert outputs match
    testing.assert_allclose(output, correct_output)