Exemple #1
0
def test_node_consistency():
    graph = CnnGenerator(10, (32, 32, 3)).generate()
    assert graph.layer_list[6].output.shape == (16, 16, 64)

    for layer in graph.layer_list:
        assert layer.output.shape == layer.output_shape

    graph.to_wider_model(5, 64)
    assert graph.layer_list[5].output.shape == (16, 16, 128)

    for layer in graph.layer_list:
        assert layer.output.shape == layer.output_shape

    graph.to_conv_deeper_model(5, 3)
    assert graph.layer_list[19].output.shape == (16, 16, 128)

    for layer in graph.layer_list:
        assert layer.output.shape == layer.output_shape

    graph.to_add_skip_model(5, 18)
    assert graph.layer_list[23].output.shape == (16, 16, 128)

    for layer in graph.layer_list:
        assert layer.output.shape == layer.output_shape

    graph.to_concat_skip_model(5, 18)
    assert graph.layer_list[25].output.shape == (16, 16, 256)

    for layer in graph.layer_list:
        assert layer.output.shape == layer.output_shape
Exemple #2
0
def test_wider_dense():
    graph = CnnGenerator(10, (32, 32, 3)).generate()
    graph.produce_model().set_weight_to_graph()
    history = [('to_wider_model', 14, 64)]
    for args in history:
        getattr(graph, args[0])(*list(args[1:]))
        graph.produce_model()
    assert legal_graph(graph)
def test_wider_conv():
    model = CnnGenerator(10, (28, 28, 3)).generate().produce_model()
    model.set_weight_to_graph()
    graph = model.graph

    assert isinstance(wider_pre_conv(graph.layer_list[1], 3), StubConv)
    assert isinstance(wider_bn(graph.layer_list[2], 3, 3, 3), StubBatchNormalization)
    assert isinstance(wider_next_conv(graph.layer_list[5], 3, 3, 3), StubConv)
Exemple #4
0
def test_long_transform():
    graph = CnnGenerator(10, (32, 32, 3)).generate()
    history = [('to_wider_model', 1, 256), ('to_conv_deeper_model', 1, 3),
               ('to_concat_skip_model', 5, 9)]
    for args in history:
        getattr(graph, args[0])(*list(args[1:]))
        graph.produce_model()
    assert legal_graph(graph)
Exemple #5
0
def test_long_transform():
    graph = CnnGenerator(10, (32, 32, 3)).generate()
    history = [('to_wider_model', 1, 256), ('to_conv_deeper_model', 1, 3),
               ('to_concat_skip_model', 5, 9)]
    for args in history:
        getattr(graph, args[0])(*list(args[1:]))
        graph.produce_model()
    assert legal_graph(graph)
Exemple #6
0
def test_wider_conv():
    model = CnnGenerator(10, (28, 28, 3)).generate().produce_model()
    model.set_weight_to_graph()
    graph = model.graph

    assert isinstance(wider_pre_conv(graph.layer_list[1], 3), StubConv)
    assert isinstance(wider_bn(graph.layer_list[2], 3, 3, 3),
                      StubBatchNormalization)
    assert isinstance(wider_next_conv(graph.layer_list[5], 3, 3, 3), StubConv)
Exemple #7
0
def test_node_consistency():
    graph = CnnGenerator(10, (32, 32, 3)).generate()
    assert graph.layer_list[6].output.shape == (16, 16, 64)

    for layer in graph.layer_list:
        assert layer.output.shape == layer.output_shape

    graph.to_wider_model(5, 64)
    assert graph.layer_list[5].output.shape == (16, 16, 128)

    for layer in graph.layer_list:
        assert layer.output.shape == layer.output_shape

    graph.to_conv_deeper_model(5, 3)
    assert graph.layer_list[19].output.shape == (16, 16, 128)

    for layer in graph.layer_list:
        assert layer.output.shape == layer.output_shape

    graph.to_add_skip_model(5, 18)
    assert graph.layer_list[23].output.shape == (16, 16, 128)

    for layer in graph.layer_list:
        assert layer.output.shape == layer.output_shape

    graph.to_concat_skip_model(5, 18)
    assert graph.layer_list[25].output.shape == (16, 16, 256)

    for layer in graph.layer_list:
        assert layer.output.shape == layer.output_shape
Exemple #8
0
 def init_search(self):
     if self.verbose:
         print('Initializing search.')
     graph = CnnGenerator(self.n_classes, self.input_shape).generate(
         self.default_model_len, self.default_model_width)
     model_id = self.model_count
     self.model_count += 1
     self.training_queue.append((graph, -1, model_id))
     self.descriptors.append(graph.extract_descriptor())
     for child_graph in default_transform(graph):
         child_id = self.model_count
         self.model_count += 1
         self.training_queue.append((child_graph, model_id, child_id))
         self.descriptors.append(child_graph.extract_descriptor())
     if self.verbose:
         print('Initialization finished.')
Exemple #9
0
 def init_search(self):
     if self.verbose:
         print('\nInitializing search.')
     graph = CnnGenerator(self.n_classes,
                          self.input_shape).generate(self.default_model_len,
                                                     self.default_model_width)
     model_id = self.model_count
     self.model_count += 1
     self.training_queue.append((graph, -1, model_id))
     self.descriptors.append(graph.extract_descriptor())
     for child_graph in default_transform(graph):
         child_id = self.model_count
         self.model_count += 1
         self.training_queue.append((child_graph, model_id, child_id))
         self.descriptors.append(child_graph.extract_descriptor())
     if self.verbose:
         print('Initialization finished.')
def test_model_trainer_classification():
    model = CnnGenerator(3, (28, 28, 3)).generate().produce_model()
    train_data, test_data = get_classification_data_loaders()
    ModelTrainer(model,
                 train_data=train_data,
                 test_data=test_data,
                 metric=Accuracy,
                 loss_function=classification_loss,
                 verbose=True).train_model(max_iter_num=3)
def test_model_trainer_regression():
    model = CnnGenerator(1, (28, 28, 3)).generate().produce_model()
    train_data, test_data = get_regression_data_loaders()
    ModelTrainer(model,
                 train_data=train_data,
                 test_data=test_data,
                 metric=MSE,
                 loss_function=regression_loss,
                 verbose=False).train_model(max_iter_num=3)
Exemple #12
0
def test_wider_dense():
    graph = CnnGenerator(10, (32, 32, 3)).generate()
    graph.produce_model().set_weight_to_graph()
    history = [('to_wider_model', 14, 64)]
    for args in history:
        getattr(graph, args[0])(*list(args[1:]))
        graph.produce_model()
    assert legal_graph(graph)
Exemple #13
0
def test_graph_size():
    graph = CnnGenerator(10, (32, 32, 3)).generate()
    assert graph.size() == 68938
Exemple #14
0
def test_deeper_conv_block():
    graph = CnnGenerator(10, (28, 28, 3)).generate()
    layers = deeper_conv_block(graph.layer_list[1], 3)
    assert len(layers) == Constant.CONV_BLOCK_DISTANCE + 1
Exemple #15
0
def test_graph_size():
    graph = CnnGenerator(10, (32, 32, 3)).generate()
    assert graph.size() == 68938
def test_search_space_limit():
    graph = CnnGenerator(10, (32, 32, 3)).generate(model_len=3, model_width=2048)
    assert to_wider_graph(graph) is None

    graph = CnnGenerator(10, (32, 32, 3)).generate(model_len=14)
    assert to_deeper_graph(graph) is None
Exemple #17
0
def test_model_trainer_regression():
    model = CnnGenerator(1, (28, 28, 3)).generate().produce_model()
    train_data, test_data = get_regression_dataloaders()
    ModelTrainer(model, train_data, test_data, MSE, regression_loss, False).train_model(max_iter_num=3)
Exemple #18
0
def test_model_trainer_classification():
    model = CnnGenerator(3, (28, 28, 3)).generate().produce_model()
    train_data, test_data = get_classification_dataloaders()
    ModelTrainer(model, train_data, test_data, Accuracy, classification_loss, False).train_model(max_iter_num=3)
Exemple #19
0
def test_default_transform():
    graphs = default_transform(CnnGenerator(10, (32, 32, 3)).generate())
    model = graphs[0].produce_model()
    model(torch.Tensor(get_conv_data()))
    assert len(graphs) == 1
    assert len(graphs[0].layer_list) == 43