def test_skip_concat_over_pooling_stub(): model = to_stub_model(get_pooling_model()) graph = Graph(model) layer_num = graph.n_layers graph.to_concat_skip_model(graph.layer_to_id[model.layers[4]], graph.layer_to_id[model.layers[11]]) assert graph.n_layers == layer_num + 2
def test_produce_keras_model(): for graph in [get_conv_dense_model(), get_add_skip_model(), get_pooling_model(), get_concat_skip_model()]: model = graph.produce_keras_model() assert isinstance(model, keras.models.Model)
def test_skip_concat_over_pooling_stub(): model = get_pooling_model() graph = Graph(model, False) layer_num = graph.n_layers graph.to_concat_skip_model(2, 15) assert graph.n_layers == layer_num + 2
def test_skip_concat_over_pooling_stub(): graph = get_pooling_model() graph.weighted = False layer_num = graph.n_layers graph.to_concat_skip_model(1, 14) assert graph.n_layers == layer_num + 6
def test_skip_concat_over_pooling_stub(): graph = get_pooling_model() graph.weighted = False layer_num = graph.n_layers graph.to_concat_skip_model(1, 11) assert graph.n_layers == layer_num + 5
def test_skip_add_over_pooling_stub(): model = get_pooling_model() graph = Graph(model, False) layer_num = graph.n_layers graph.to_add_skip_model(1, 10) assert graph.n_layers == layer_num + 3
def test_keras_model(): for graph in [get_conv_dense_model(), get_add_skip_model(), get_pooling_model(), get_concat_skip_model()]: keras_model = KerasModel(graph) keras_model.set_weight_to_graph() assert isinstance(keras_model, KerasModel)
def test_produce_keras_model(): for graph in [ get_conv_dense_model(), get_add_skip_model(), get_pooling_model(), get_concat_skip_model() ]: model = graph.produce_keras_model() assert isinstance(model, keras.models.Model)
def test_skip_add_over_pooling(): model = get_pooling_model() graph = Graph(model) new_model = graph.to_add_skip_model(model.layers[4], model.layers[11]) 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)
def test_keras_model(): for graph in [ get_conv_dense_model(), get_add_skip_model(), get_pooling_model(), get_concat_skip_model() ]: keras_model = KerasModel(graph) keras_model.set_weight_to_graph() assert isinstance(keras_model, KerasModel)
def test_skip_concat_over_pooling(): model = get_pooling_model() graph = Graph(model) new_model = graph.to_concat_skip_model(model.layers[4], model.layers[11]) 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)) < 1e-4
def test_skip_add_over_pooling(): model = get_pooling_model() graph = Graph(model, True) graph.to_add_skip_model(2, 10) 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.array_equal(output1, output2)
def test_skip_add_over_pooling(): model = get_pooling_model() graph = NetworkMorphismGraph(model) graph.to_add_skip_model(graph.layer_to_id[model.layers[4]], graph.layer_to_id[model.layers[11]]) 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.array_equal(output1, output2)
def test_skip_concat_over_pooling(): model = get_pooling_model() graph = Graph(model, True) graph.to_concat_skip_model(6, 11) graph.to_concat_skip_model(6, 11) graph = Graph(graph.produce_model(), True) 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
def test_skip_concat_over_pooling(): model = get_pooling_model() graph = NetworkMorphismGraph(model) graph.to_concat_skip_model(graph.layer_to_id[model.layers[4]], graph.layer_to_id[model.layers[8]]) graph.to_concat_skip_model(graph.layer_to_id[model.layers[4]], graph.layer_to_id[model.layers[8]]) graph = NetworkMorphismGraph(graph.produce_model()) 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
def test_skip_add_over_pooling(): graph = get_pooling_model() model = graph.produce_model() graph = deepcopy(graph) graph.to_add_skip_model(1, 10) new_model = graph.produce_model() input_data = torch.Tensor(get_conv_data()) model.eval() new_model.eval() output1 = model(input_data) output2 = new_model(input_data) assert (output1 - output2).abs().sum() < 1e-4
def test_skip_add_over_pooling(): graph = get_pooling_model() model = graph.produce_model() graph = deepcopy(graph) graph.to_add_skip_model(1, 8) new_model = graph.produce_model() input_data = torch.Tensor(get_conv_data()) model.eval() new_model.eval() output1 = model(input_data) output2 = new_model(input_data) assert (output1 - output2).abs().sum() < 1e-4
def test_legal_graph2(): graph = get_pooling_model() graph.to_concat_skip_model(1, 5) assert legal_graph(graph) graph.to_concat_skip_model(1, 5) assert not legal_graph(graph)
def test_legal_graph(): graph = get_pooling_model() graph.to_add_skip_model(1, 4) assert legal_graph(graph) graph.to_add_skip_model(1, 4) assert not legal_graph(graph)
def test_transform(): models = transform(Graph(to_stub_model(get_pooling_model()))) assert len(models) == constant.N_NEIGHBORS
def test_legal_graph2(): graph = get_pooling_model() graph.to_concat_skip_model(1, 4) assert legal_graph(graph) graph.to_concat_skip_model(1, 4) assert not legal_graph(graph)
def test_legal_graph(): graph = Graph(get_pooling_model(), False) graph.to_add_skip_model(1, 5) assert legal_graph(graph) graph.to_add_skip_model(1, 5) assert not legal_graph(graph)
def test_transform(): models = transform(get_pooling_model()) assert len(models) == Constant.N_NEIGHBOURS
def test_wider_dense(): model = to_wider_graph(Graph(to_stub_model(get_pooling_model()))) assert isinstance(model, Graph)
def test_transform(): models = transform(Graph(get_pooling_model(), False)) assert len(models) == 12
def test_legal_graph2(): graph = Graph(get_pooling_model(), False) graph.to_concat_skip_model(2, 6) assert legal_graph(graph) graph.to_concat_skip_model(2, 6) assert not legal_graph(graph)
def test_skip(): model = to_skip_connection_graph(get_pooling_model()) assert isinstance(model, Graph)
def test_wider_dense(): model = to_wider_graph(Graph(get_pooling_model(), False)) assert isinstance(model, Graph)
def test_wider(): model = to_wider_graph(get_pooling_model()) assert isinstance(model, Graph)
def test_transform(): models = transform(Graph(get_pooling_model(), False)) assert len(models) == constant.N_NEIGHBOURS