Esempio n. 1
0
def test_sequential_multi_layer():
    model = keras.models.Sequential()
    model.add(
        keras.layers.Dense(4,
                           use_bias=False,
                           activation=None,
                           input_shape=(2, )))
    model.add(keras.layers.Dense(8, use_bias=False, activation=None))
    model.build()

    graph = KerasConverter(batch_size=1).convert(model)

    assert_equal(len(graph.inputs), 1)

    ops = traverse.listup_operators(graph)
    assert_equal(len(ops), 2)
    assert_equal(type(ops[0]), Linear)
    assert_equal(type(ops[1]), Linear)

    assert_equal(len(graph.outputs), 1)
Esempio n. 2
0
def test_residual():
    x = keras.layers.Input(shape=(4, ))
    h1 = keras.layers.Dense(8, use_bias=False, activation=None)(x)
    h21 = keras.layers.Dense(4, use_bias=False, activation=None)(h1)
    h22 = keras.layers.Dense(4, use_bias=False, activation=None)(h1)
    y = keras.layers.add([h21, h22])
    model = keras.models.Model([x], [y])
    model.build(input_shape=(1, 4))

    graph = KerasConverter(batch_size=1).convert(model)

    assert_equal(len(graph.inputs), 1)

    ops = traverse.listup_operators(graph)
    assert_equal(len(ops), 4)
    assert_equal(type(ops[0]), Linear)
    assert_equal(type(ops[1]), Linear)
    assert_equal(type(ops[2]), Linear)
    assert_equal(type(ops[3]), ElementwiseAdd)

    assert_equal(len(graph.outputs), 1)