def test_bce_get_layer_method(weight, reduction, pos_weight): x = BCELoss(weight=weight, reduction=reduction, pos_weight=pos_weight) details = x.get_loss_function() assert isinstance(details, dict) == True assert issubclass(details["loss_function"], _BCEWithLogitsLoss) == True assert isinstance(details["keyword_arguments"], dict) == True assert torch.all(torch.eq(details["keyword_arguments"]["weight"], torch.tensor(weight).float())) == True assert details["keyword_arguments"]["reduction"] == reduction assert torch.all(torch.eq(details["keyword_arguments"]["pos_weight"], torch.tensor(pos_weight).float())) == True
def test_bce_get_layer_method_with_default_parameters(): x = BCELoss() details = x.get_loss_function() assert isinstance(details, dict) == True assert issubclass(details["loss_function"], _BCEWithLogitsLoss) == True assert isinstance(details["keyword_arguments"], dict) == True assert details["keyword_arguments"]["weight"] == None assert details["keyword_arguments"]["reduction"] == 'mean' assert details["keyword_arguments"]["pos_weight"] == None
def test_bce_should_throw_value_error(weight, reduction, pos_weight): with pytest.raises(ValueError) as ex: x = BCELoss(weight=weight, reduction=reduction, pos_weight=pos_weight)