def test_edit_distance2(): descriptor1 = get_conv_dense_model().extract_descriptor() graph = get_conv_dense_model() graph.to_wider_model(4, 6) graph.to_wider_model(9, 3) descriptor2 = graph.extract_descriptor() assert edit_distance(descriptor1, descriptor2) == 2.0 / 9
def test_edit_distance2(): descriptor1 = get_conv_dense_model().extract_descriptor() graph = get_conv_dense_model() graph.to_conv_deeper_model(1, 3) graph.to_wider_model(5, 6) graph.to_wider_model(17, 3) descriptor2 = graph.extract_descriptor() assert edit_distance(descriptor1, descriptor2, 1.0) == 1.5
def test_dense_deeper_stub(): graph = get_conv_dense_model() graph.weighted = False layer_num = graph.n_layers graph.to_dense_deeper_model(9) 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_dense_deeper_stub(): model = get_conv_dense_model() graph = Graph(model, False) layer_num = graph.n_layers graph.to_dense_deeper_model(5) assert graph.n_layers == layer_num + 2
def test_dense_deeper_stub(): model = to_stub_model(get_conv_dense_model()) graph = Graph(model) layer_num = graph.n_layers graph.to_dense_deeper_model(graph.layer_to_id[model.layers[5]]) assert graph.n_layers == layer_num + 1
def test_dense_deeper_stub(): graph = get_conv_dense_model() graph.weighted = False layer_num = graph.n_layers graph.to_dense_deeper_model(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_dense_deeper(): model = get_conv_dense_model() graph = Graph(model) new_model = graph.to_dense_deeper_model(model.layers[5]) 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(output1 - output2) == 0
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_dense_deeper(): model = get_conv_dense_model() graph = NetworkMorphismGraph(model) graph.to_dense_deeper_model(graph.layer_to_id[model.layers[5]]) 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-4
def test_dense_deeper(): model = get_conv_dense_model() graph = Graph(model, True) graph.to_dense_deeper_model(5) 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-4
def test_dense_deeper(): graph = get_conv_dense_model() model = graph.produce_model() graph = deepcopy(graph) graph.to_dense_deeper_model(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-3
def test_dense_deeper(): graph = get_conv_dense_model() model = graph.produce_model() graph = deepcopy(graph) graph.to_dense_deeper_model(9) 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-3
def test_deeper(_, _1): model = to_deeper_model(get_conv_dense_model()) assert model is None
def test_conv_deeper_stub(): graph = get_conv_dense_model() layer_num = graph.n_layers graph.to_conv_deeper_model(4, 3) assert graph.n_layers == layer_num + 3
def test_skip_connection_layer_ids(): graph = get_conv_dense_model() assert len(graph.skip_connection_layer_ids()) == 1
def test_skip(_, _1): model = to_skip_connection_model(get_conv_dense_model()) assert model is None
def test_deep_layer_ids(): graph = get_conv_dense_model() assert len(graph.deep_layer_ids()) == 3
def test_wide_layer_ids(): graph = get_conv_dense_model() assert len(graph.wide_layer_ids()) == 2
def test_transform(_, _1, _2, _3, _4): models = transform(get_conv_dense_model()) assert len(models) == constant.N_NEIGHBORS
def test_wider_next_dense(): real_layer = get_conv_dense_model().layer_list[9] layer = StubDense(real_layer.input_units, real_layer.units) layer.set_weights(real_layer.get_weights()) new_layer = wider_next_dense(layer, 3, 3, 3) assert new_layer.get_weights()[0].shape == (5, 6144)
def test_skip_connection_layer_ids(): model = get_conv_dense_model() graph = Graph(model, True) assert len(graph.skip_connection_layer_ids()) == 0
def test_wider(_): model = to_wider_model(get_conv_dense_model()) assert model is None
def test_wide_layer_ids(): model = get_conv_dense_model() graph = Graph(model, True) assert len(graph.wide_layer_ids()) == 1
def test_wider_next_dense(): layer = get_conv_dense_model().layers[5] new_layer = wider_next_dense(layer, 3, 3, 3) assert new_layer.get_weights()[0].shape == (150, 5)
def test_conv_deeper_stub(): graph = get_conv_dense_model() layer_num = graph.n_layers graph.to_conv_deeper_model(5, 3) assert graph.n_layers == layer_num + 4
def test_deeper(): model = to_deeper_graph(get_conv_dense_model()) assert isinstance(model, Graph)
def test_wider_next_dense(): real_layer = get_conv_dense_model().layers[6] layer = StubDense(real_layer.units, 'relu') layer.set_weights(real_layer.get_weights()) new_layer = wider_next_dense(layer, 3, 3, 3) assert new_layer.get_weights()[0].shape == (6, 5)