示例#1
0
    def bneck(s, skippable):
        """Construct a spec for an inverted bottleneck layer."""
        possible_filter_multipliers = [3.0, 6.0]
        possible_kernel_sizes = [3, 5, 7]
        choices = []

        if collapse_shared_ops:
            kernel_size = schema.OneOf(possible_kernel_sizes,
                                       basic_specs.OP_TAG)
            expansion_filters = schema.OneOf([
                basic_specs.FilterMultiplier(multiplier)
                for multiplier in possible_filter_multipliers
            ], basic_specs.FILTERS_TAG)
            choices.append(
                DepthwiseBottleneckSpec(kernel_size=kernel_size,
                                        expansion_filters=expansion_filters,
                                        use_squeeze_and_excite=False,
                                        strides=s,
                                        activation=RELU))
        else:
            for multiplier in possible_filter_multipliers:
                for kernel_size in possible_kernel_sizes:
                    choices.append(
                        DepthwiseBottleneckSpec(
                            kernel_size=kernel_size,
                            expansion_filters=basic_specs.FilterMultiplier(
                                multiplier),
                            use_squeeze_and_excite=False,
                            strides=s,
                            activation=RELU))

        if skippable:
            choices.append(basic_specs.ZeroSpec())
        return schema.OneOf(choices, basic_specs.OP_TAG)
    def test_scale_conv_tower_spec_filter_multipliers(self):
        model_spec = basic_specs.ConvTowerSpec(blocks=[
            basic_specs.block(layers=[
                schema.OneOf([
                    basic_specs.FilterMultiplier(3.0),
                    basic_specs.FilterMultiplier(6.0)
                ], basic_specs.FILTERS_TAG)
            ],
                              filters=48)
        ],
                                               filters_base=8)
        scaled_spec = search_space_utils.scale_conv_tower_spec(
            model_spec, multipliers=(0.5, 1, 2), base=8)

        # FilterMultiplier objects should not be affected by the scaling function.
        self.assertEqual(scaled_spec.blocks[0].layers[0].choices, [
            basic_specs.FilterMultiplier(3.0),
            basic_specs.FilterMultiplier(6.0),
        ])

        # However, absolute filter sizes should still be scaled.
        self.assertEqual(scaled_spec.blocks[0].filters.choices, [24, 48, 96])
示例#3
0
    def bneck(kernel, input_size, exp_size, se, s, act):
        if use_relative_filter_sizes:
            # The expanded filter size will be computed relative to the input filter
            # size. Separate logic in the model builder code ensures that the expanded
            # filter size will be an integer multiple of `model_spec.filters_base`.
            filters = basic_specs.FilterMultiplier(exp_size / input_size)
        else:
            filters = exp_size

        return DepthwiseBottleneckSpec(kernel_size=kernel,
                                       expansion_filters=choose_filters(
                                           [filters]),
                                       use_squeeze_and_excite=se,
                                       strides=s,
                                       activation=act)
示例#4
0
 def bneck(input_size, se, s, act):
     """Construct a DepthwiseBottleneckSpec namedtuple."""
     if use_relative_expansion_filters:
         expansion_filters = sorted({
             basic_specs.FilterMultiplier(expansion)
             for expansion in expansion_multipliers
         })
     else:
         expansion_filters = sorted({
             search_space_utils.scale_filters(input_size, expansion, base=8)
             for expansion in expansion_multipliers
         })
     if search_squeeze_and_excite:
         # Replace the default value of the argument 'se' with a OneOf node.
         se = schema.OneOf([False, True], basic_specs.OP_TAG)
     return DepthwiseBottleneckSpec(
         kernel_size=schema.OneOf([3, 5, 7], basic_specs.OP_TAG),
         expansion_filters=choose_filters(expansion_filters),
         use_squeeze_and_excite=se,
         strides=s,
         activation=act)