def test_psnr():
    psnr = PSNR()
    assert psnr.name == 'psnr'

    pred = torch.tensor([0., 1, 2, 3])
    target = torch.tensor([0., 1, 2, 2])
    score = psnr(pred, target)
    assert isinstance(score, torch.Tensor)
Пример #2
0
def test_reduction_for_dim_none(reduction):
    match = f"The `reduction={reduction}` will not have any effect when `dim` is None."
    with pytest.warns(UserWarning, match=match):
        PSNR(reduction=reduction, dim=None)

    with pytest.warns(UserWarning, match=match):
        psnr(_inputs[0].preds,
             _inputs[0].target,
             reduction=reduction,
             dim=None)
def test_psnr_base_e_wider_range(pred, target, exp):
    psnr = PSNR(data_range=4, base=2.718281828459045)
    assert psnr.name == 'psnr'
    score = psnr(pred=torch.tensor(pred), target=torch.tensor(target))
    assert isinstance(score, torch.Tensor)
    assert pytest.approx(score.item(), rel=1e-3) == exp
def test_psnr(pred, target, exp):
    psnr = PSNR()
    assert psnr.name == 'psnr'
    score = psnr(pred=torch.tensor(pred), target=torch.tensor(target))
    assert isinstance(score, torch.Tensor)
    assert pytest.approx(score.item(), rel=1e-3) == exp
Пример #5
0
def test_missing_data_range():
    with pytest.raises(ValueError):
        PSNR(data_range=None, dim=0)

    with pytest.raises(ValueError):
        psnr(_inputs[0].preds, _inputs[0].target, data_range=None, dim=0)