Esempio n. 1
0
def test_l1_regularizer09():
    scale = 0.5
    weights = Tensor([[False, False], [False, False]])
    try:
        net = nn.L1Regularizer(scale)
        net(weights)
    except TypeError:
        assert True
def test_l1_regularizer08():
    scale = 0.5
    net = nn.L1Regularizer(scale)
    weights = Tensor(np.array([[1.0, -2.0], [-3.0, 4.0]]).astype(np.float32))
    output = net(weights)
    expect = 5.0
    print("output : ", output.asnumpy())
    assert np.all(output.asnumpy() == expect)
Esempio n. 3
0
def test_l1_regularizer_input_tuple():
    scale = 0.5
    net = nn.L1Regularizer(scale)
    weights = (1, 2, 3, 4)
    try:
        output = net(weights)
        print("output : ", output.asnumpy())
    except TypeError:
        assert True
Esempio n. 4
0
 def __init__(self, scale):
     super(Net_l1_regularizer, self).__init__()
     self.l1_regularizer = nn.L1Regularizer(scale)