Пример #1
0
def test__check_shape():
    acc = Accuracy()

    # Check squeezed dimensions
    y_pred, y = acc._check_shape((torch.randint(0, 2, size=(10, 1, 5, 6)).type(torch.LongTensor),
                                  torch.randint(0, 2, size=(10, 5, 6)).type(torch.LongTensor)))
    assert y_pred.shape == (10, 5, 6)
    assert y.shape == (10, 5, 6)

    y_pred, y = acc._check_shape((torch.randint(0, 2, size=(10, 5, 6)).type(torch.LongTensor),
                                  torch.randint(0, 2, size=(10, 1, 5, 6)).type(torch.LongTensor)))
    assert y_pred.shape == (10, 5, 6)
    assert y.shape == (10, 5, 6)
Пример #2
0
def test__check_shape():
    acc = Accuracy()

    with pytest.raises(ValueError):
        acc._check_shape((torch.randint(0, 2, size=(10, 1, 5, 12)).long(), torch.randint(0, 2, size=(10, 5, 6)).long()))

    with pytest.raises(ValueError):
        acc._check_shape((torch.randint(0, 2, size=(10, 1, 6)).long(), torch.randint(0, 2, size=(10, 5, 6)).long()))

    with pytest.raises(ValueError):
        acc._check_shape((torch.randint(0, 2, size=(10, 1)).long(), torch.randint(0, 2, size=(10, 5)).long()))
Пример #3
0
def test__check_shape():
    acc = Accuracy()

    with pytest.raises(ValueError, match=r"y and y_pred must have compatible shapes"):
        acc._check_shape((torch.randint(0, 2, size=(10, 1, 5, 12)).long(), torch.randint(0, 2, size=(10, 5, 6)).long()))

    with pytest.raises(ValueError, match=r"y and y_pred must have compatible shapes"):
        acc._check_shape((torch.randint(0, 2, size=(10, 1, 6)).long(), torch.randint(0, 2, size=(10, 5, 6)).long()))

    with pytest.raises(ValueError, match=r"y and y_pred must have compatible shapes"):
        acc._check_shape((torch.randint(0, 2, size=(10, 1)).long(), torch.randint(0, 2, size=(10, 5)).long()))