Beispiel #1
0
def test_crop_cuda():
    inp = torch.cuda.FloatTensor([[
        [1, 1, 0, 0],
        [1, 1, 0, 0],
        [0, 0, 1, 1],
        [0, 0, 1, 1],
    ]])
    expected = torch.cuda.FloatTensor([[
        [2, 2, 2, 2, 2],
        [1, 0, 0, 2, 2],
    ]])
    actual = crop(inp, -1, 1, 2, 5, padding_mode='constant', fill=2)
    assert_allclose(actual, expected)
Beispiel #2
0
def test_crop():
    inp = torch.FloatTensor([[
        [1, 1, 0, 0],
        [1, 1, 0, 0],
        [0, 0, 1, 1],
        [0, 0, 1, 1],
    ]])
    expected = torch.FloatTensor([[
        [1, 0],
        [0, 1],
        [0, 1],
    ]])
    actual = crop(inp, 1, 1, 3, 2)
    assert_allclose(actual, expected)
Beispiel #3
0
def test_crop_random(data, t, l, w, h, device):
    inp = torch.from_numpy(data).to(device)
    actual = crop(inp, t, l, h, w)
    assert actual.shape == (data.shape[0], h, w)