コード例 #1
0
ファイル: test_fsim.py プロジェクト: photosynthesis-team/piq
def test_fsim_loss_reduction(x, y) -> None:
    loss = FSIMLoss(reduction='mean')
    measure = loss(x, y)
    assert measure.dim(
    ) == 0, f'FSIM with `mean` reduction must return 1 number, got {len(measure)}'

    loss = FSIMLoss(reduction='sum')
    measure = loss(x, y)
    assert measure.dim(
    ) == 0, f'FSIM with `mean` reduction must return 1 number, got {len(measure)}'

    loss = FSIMLoss(reduction='none')
    measure = loss(x, y)
    assert len(measure) == x.size(0), \
        f'FSIM with `none` reduction must have length equal to number of images, got {len(measure)}'

    loss = FSIMLoss(reduction='random string')
    with pytest.raises(ValueError):
        loss(x, y)
コード例 #2
0
ファイル: test_fsim.py プロジェクト: akamaus/piq
def test_fsim_loss_reduction(prediction: torch.Tensor,
                             target: torch.Tensor) -> None:
    loss = FSIMLoss(reduction='mean')
    measure = loss(prediction, target)
    assert measure.dim(
    ) == 0, f'FSIM with `mean` reduction must return 1 number, got {len(measure)}'

    loss = FSIMLoss(reduction='sum')
    measure = loss(prediction, target)
    assert measure.dim(
    ) == 0, f'FSIM with `mean` reduction must return 1 number, got {len(measure)}'

    loss = FSIMLoss(reduction='none')
    measure = loss(prediction, target)
    assert len(measure) == prediction.size(0), \
        f'FSIM with `none` reduction must have length equal to number of images, got {len(measure)}'

    loss = FSIMLoss(reduction='random string')
    with pytest.raises(KeyError):
        loss(prediction, target)
コード例 #3
0
ファイル: test_fsim.py プロジェクト: photosynthesis-team/piq
def test_fsim_loss_computes_grad(x, y, device: str) -> None:
    x.requires_grad_()
    loss_value = FSIMLoss()(x.to(device), y.to(device))
    loss_value.backward()
    assert x.grad is not None, 'Expected non None gradient of leaf variable'
コード例 #4
0
ファイル: test_fsim.py プロジェクト: akamaus/piq
def test_fsim_loss_computes_grad(prediction: torch.Tensor,
                                 target: torch.Tensor, device: str) -> None:
    prediction.requires_grad_()
    loss_value = FSIMLoss()(prediction, target)
    loss_value.backward()
    assert prediction.grad is not None, 'Expected non None gradient of leaf variable'