Exemplo n.º 1
0
    def test_network_by_global_fraction_deleting(self):
        random_fractions = numpy.random.uniform(low=0, high=1, size=5)
        for fraction in random_fractions:
            for number_of_layers in [1, 3, 6, 10, 20]:
                for shape in self.shapes:
                    network = get_random_network_mock(
                        number_of_layers=number_of_layers,
                        shape_of_layer=shape)
                    indicators = [
                        self.get_random_indicators(shape)
                        for x in xrange(number_of_layers)
                    ]

                    network_after_deleting = deepcopy(network)
                    delete_weights_by_global_fraction(
                        network_after_deleting.weighted_layers, fraction,
                        indicators)

                    new_zeros = get_fraction_of_zeros_in_network(
                        network=network_after_deleting)
                    difference = abs(new_zeros - fraction)
                    network_size = sum([
                        layer.W.size
                        for layer in network_after_deleting.weighted_layers
                    ])
                    assert_true(difference <= 1. / network_size)
Exemplo n.º 2
0
    def test_smallest_indicator_size(self):
        for number_of_layers in [1, 3, 5, 7, 10, 20]:
            for size_of_layer in [1, 10, 100, 500]:
                network = get_random_network_mock(
                    number_of_layers=number_of_layers,
                    shape_of_layer=size_of_layer)
                indicators = get_smallest_indicators(network.weighted_layers)

                assert_equal(number_of_layers, len(indicators))
                for layer in xrange(number_of_layers):
                    assert_equal(size_of_layer, len(indicators[layer]))
Exemplo n.º 3
0
    def test_sharpen_filters_indicators_shape(self):
        for number_of_layers in [1, 3, 5, 7, 10, 20]:
            for layers_shape in [(1, 1, 5, 5), (3, 5, 5, 30), (6, 1, 10, 10)]:
                network = get_random_network_mock(
                    number_of_layers=number_of_layers,
                    shape_of_layer=layers_shape
                )
                indicators = get_filters_indicators(
                    layers=network.weighted_layers,
                    bilateral_filter_args=self.bilateral_filter_args
                )

                assert_equal(number_of_layers, len(indicators))
                for layer in xrange(number_of_layers):
                    assert_equal(layers_shape, indicators[layer].shape)
Exemplo n.º 4
0
 def setUp(self):
     self.network = get_random_network_mock()