Beispiel #1
0
def test_conv_deeper_stub():
    model = get_conv_model()
    graph = Graph(to_stub_model(model))
    layer_num = graph.n_layers
    graph.to_conv_deeper_model(3, 3)

    assert graph.n_layers == layer_num + 3
Beispiel #2
0
def test_conv_deeper_stub():
    model = get_conv_model()
    graph = Graph(model, False)
    layer_num = graph.n_layers
    graph.to_conv_deeper_model(6, 3)

    assert graph.n_layers == layer_num + 4
Beispiel #3
0
def test_wider_conv():
    model = to_stub_model(get_conv_model(), True)

    assert isinstance(wider_pre_conv(model.layers[2], 3), StubConv)
    assert isinstance(wider_bn(model.layers[3], 3, 3, 3),
                      StubBatchNormalization)
    assert isinstance(wider_next_conv(model.layers[6], 3, 3, 3), StubConv)
Beispiel #4
0
def test_conv_deeper():
    model = get_conv_model()
    graph = Graph(model)
    new_model = graph.to_conv_deeper_model(model.layers[4], 3)
    input_data = get_conv_data()

    output1 = model.predict_on_batch(input_data).flatten()
    output2 = new_model.predict_on_batch(input_data).flatten()

    assert abs(np.sum(output1 - output2)) < 0.2
Beispiel #5
0
def test_skip_add():
    model = get_conv_model()
    graph = Graph(model)
    new_model = graph.to_add_skip_model(model.layers[1], model.layers[4])
    input_data = get_conv_data()

    output1 = model.predict_on_batch(input_data).flatten()
    output2 = new_model.predict_on_batch(input_data).flatten()

    assert np.array_equal(output1, output2)
Beispiel #6
0
def test_conv_deeper():
    model = get_conv_model()
    graph = Graph(model, True)
    graph.to_conv_deeper_model(6, 3)
    new_model = graph.produce_model()
    input_data = get_conv_data()

    output1 = model.predict_on_batch(input_data).flatten()
    output2 = new_model.predict_on_batch(input_data).flatten()

    assert np.sum(np.abs(output1 - output2)) < 4e-1
Beispiel #7
0
def test_deeper_conv_block():
    model = get_conv_model()
    layers = deeper_conv_block(model.layers[1], 3)
    output_tensor = layers[0](model.outputs[0])
    output_tensor = layers[1](output_tensor)
    output_tensor = layers[2](output_tensor)
    new_model = Model(inputs=model.inputs, outputs=output_tensor)
    input_data = get_conv_data()
    output1 = model.predict_on_batch(input_data).flatten()
    output2 = new_model.predict_on_batch(input_data).flatten()
    assert np.sum(np.abs(output1 - output2)) < 1e-1
Beispiel #8
0
def test_conv_deeper():
    model = get_conv_model()
    graph = NetworkMorphismGraph(model)
    graph.to_conv_deeper_model(graph.layer_to_id[model.layers[4]], 3)
    new_model = graph.produce_model()
    input_data = get_conv_data()

    output1 = model.predict_on_batch(input_data).flatten()
    output2 = new_model.predict_on_batch(input_data).flatten()

    assert np.sum(np.abs(output1 - output2)) < 1e-1
Beispiel #9
0
def test_wider_conv():
    model = get_conv_model()

    layer1 = wider_pre_conv(model.layers[1], 3)
    layer2 = wider_bn(model.layers[2], 3, 3, 3)
    layer3 = wider_next_conv(model.layers[4], 3, 3, 3)

    input_tensor = Input(shape=(5, 5, 3))
    output_tensor = layer1(input_tensor)
    output_tensor = layer2(output_tensor)
    output_tensor = Activation('relu')(output_tensor)
    output_tensor = layer3(output_tensor)
    output_tensor = BatchNormalization()(output_tensor)
    output_tensor = Activation('relu')(output_tensor)
    model2 = Model(inputs=input_tensor, outputs=output_tensor)

    random_input = get_conv_data()
    output1 = model.predict_on_batch(random_input)
    output2 = model2.predict_on_batch(random_input)
    assert np.sum(np.abs(output1.flatten() - output2.flatten())) < 1e-1
Beispiel #10
0
def test_graph():
    graph = Graph(get_conv_model())
    assert graph.n_nodes == 13
Beispiel #11
0
def test_wider_bn():
    bn_layer = get_conv_model().layers[2]
    new_bn_layer = wider_bn(bn_layer, 1, 3, 4)
    assert new_bn_layer.get_weights()[0].shape[0] == 7
Beispiel #12
0
def test_deeper_conv_block():
    model = to_stub_model(get_conv_model(), True)
    layers = deeper_conv_block(model.layers[2], 3)
    assert len(layers) == constant.CONV_BLOCK_DISTANCE + 1