def test_style_loss_raises_if_wrong_reduction(x, y) -> None: for mode in ['mean', 'sum', 'none']: StyleLoss(reduction=mode)(x, y) for mode in [None, 'n', 2]: with pytest.raises(ValueError): StyleLoss(reduction=mode)(x, y)
def test_style_loss_computes_grad(input_tensors: Tuple[torch.Tensor, torch.Tensor], device: str) -> None: x, y = input_tensors x.requires_grad_() loss_value = StyleLoss()(x.to(device), y.to(device)) loss_value.backward() assert x.grad is not None, NONE_GRAD_ERR_MSG
def test_style_loss_raises_if_wrong_reduction(prediction: torch.Tensor, target: torch.Tensor) -> None: for mode in ['mean', 'sum', 'none']: StyleLoss(reduction=mode)(prediction, target) for mode in [None, 'n', 2]: with pytest.raises(KeyError): StyleLoss(reduction=mode)(prediction, target)
def test_style_loss_computes_grad(input_tensors: Tuple[torch.Tensor, torch.Tensor], device: str) -> None: prediction, target = input_tensors prediction.requires_grad_() loss_value = StyleLoss()(prediction.to(device), target.to(device)) loss_value.backward() assert prediction.grad is not None, NONE_GRAD_ERR_MSG
def test_style_loss_forward(input_tensors: Tuple[torch.Tensor, torch.Tensor], device: str) -> None: x, y = input_tensors loss = StyleLoss() loss(x.to(device), y.to(device))
def test_style_loss_init() -> None: StyleLoss()
def test_style_loss_forward(input_tensors: Tuple[torch.Tensor, torch.Tensor], device: str) -> None: prediction, target = input_tensors loss = StyleLoss() loss(prediction.to(device), target.to(device))