test_top_level1.py 1.24 KB
Newer Older
tqchen committed
1
import nnvm.symbol as sym
2
import nnvm.graph as graph
tqchen committed
3

4
def test_dense():
tqchen committed
5
    x = sym.Variable('x')
6 7 8
    x1 = sym.dense(x, units=3, name="dense")
    x2 = sym.flatten(x1)
    x3 = sym.softmax(x2)
Yuwei HU committed
9
    assert x3.list_input_names() == ['x', 'dense_weight', 'dense_bias']
tqchen committed
10

11

12
def test_concatenate_split():
tqchen committed
13 14
    x = sym.Variable('x')
    y = sym.Variable('y')
15
    y = sym.concatenate(x, y)
tqchen committed
16
    assert y.list_input_names() == ['x', 'y']
17 18 19
    z = sym.split(y, indices_or_sections=10)
    assert len(z.list_output_names()) == 10
    z = sym.split(y, indices_or_sections=[10, 20])
20
    assert len(z.list_output_names()) == 3
21

22 23 24 25 26
def test_expand_dims():
    x = sym.Variable('x')
    y = sym.expand_dims(x, axis=1, num_newaxis=2)
    assert y.list_input_names() == ['x']

tqchen committed
27

28 29 30 31 32 33
def test_unary():
    x = sym.Variable('x')
    x = sym.exp(x)
    x = sym.log(x)
    x = sym.sigmoid(x)
    x = sym.tanh(x)
34
    x = sym.relu(x)
35 36
    assert x.list_input_names() == ['x']

37

38 39 40 41 42 43
def test_batchnorm():
    x = sym.Variable('x')
    x = sym.batch_norm(x, name="bn")
    assert x.list_input_names() == [
        "x", "bn_gamma", "bn_beta", "bn_moving_mean", "bn_moving_var"]

tqchen committed
44

tqchen committed
45
if __name__ == "__main__":
46
    test_concatenate_split()
47
    test_expand_dims()
48
    test_dense()
49 50
    test_unary()
    test_batchnorm()