Esempio n. 1
0
 def _build_head_layers(self, model_args):
     self._head_layers = build_conv_bn_act(self._global_params,
                                           model_args.feature_mix_layer,
                                           add_bn=True,
                                           act_fn=self.act_fn)
     self._head_layers.append(
         GlobalAvgPool(self._global_params, keep_dims=True))
Esempio n. 2
0
    def _build_proj(self, output_filters):
        kwargs = dict(
            cls=Conv2D.__name__,
            output_filters=output_filters,
            kernel_size=[1, 1],
            strides=[1, 1])

        self._proj_layers = build_conv_bn_act(self._global_params, kwargs, add_bn=True, act_fn=None)
Esempio n. 3
0
    def _build_dwise(self, output_filters):
        kernel_size = self._block_args.kernel_size
        kwargs = dict(
            cls=DepthwiseConv2D.__name__,
            kernel_size=[kernel_size, kernel_size],
            strides=self._block_args.strides)

        self._dwise_layers = build_conv_bn_act(self._global_params, kwargs, add_bn=True, act_fn=self.act_fn)
Esempio n. 4
0
 def _build_expand(self, output_filters):
     if self._block_args.expand_ratio != 1:
         kwargs = dict(
             cls=Conv2D.__name__,
             output_filters=output_filters,
             kernel_size=[1, 1],
             strides=[1, 1])
     else:
         kwargs = None
     self._expand_layers = build_conv_bn_act(self._global_params, kwargs, add_bn=True, act_fn=self.act_fn)
Esempio n. 5
0
    def _build_dwise(self, output_filters):
        kernel_sizes = self._block_args.kernel_size
        input_filters = self._block_args.input_filters
        expand_ratios = self._block_args.expand_ratio
        filter_splits = [int(input_filters * er) for er in expand_ratios]
        assert self.expand_filters == sum(filter_splits)
        kwargs = dict(
            cls=MixConv.__name__,
            kernel_sizes=kernel_sizes,
            filter_splits=filter_splits,
            strides=self._block_args.strides)

        self._dwise_layers = build_conv_bn_act(self._global_params, kwargs, add_bn=True, act_fn=self.act_fn)
Esempio n. 6
0
 def _build_head_layers(self, model_args):
     final_expand_layer = model_args.get('final_expand_layer')
     if final_expand_layer:
         self._head_layers = build_conv_bn_act(
             self._global_params,
             model_args.final_expand_layer,
             add_bn=True,
             act_fn=self.act_fn)
         gap = GlobalAvgPool(self._global_params, keep_dims=True)
         feature_mix_layer = graph.construct_with_args(
             self._global_params, **model_args.feature_mix_layer)
         final_act_fn = Activation(self._global_params, self.act_fn)
         self._head_layers.extend([gap, feature_mix_layer, final_act_fn])
     else:
         super(MBV3CompatJsonNet, self)._build_head_layers(model_args)
Esempio n. 7
0
    def _build_expand(self, output_filters):
        kernel_size = self._block_args.kernel_size
        if self.kernel_front:
            expand_ksize = [kernel_size, kernel_size]
        else:
            expand_ksize = [self.default_ksize, self.default_ksize]

        if self.stride_front:
            expand_strides = self._block_args.strides
        else:
            expand_strides = [1, 1]

        kwargs = dict(cls=Conv2D.__name__,
                      output_filters=output_filters,
                      kernel_size=expand_ksize,
                      strides=expand_strides)
        self._expand_layers = build_conv_bn_act(self._global_params,
                                                kwargs,
                                                add_bn=True,
                                                act_fn=self.act_fn)
Esempio n. 8
0
    def _build_proj(self, output_filters):
        kernel_size = self._block_args.kernel_size
        if self.kernel_front:
            proj_ksize = [self.default_ksize, self.default_ksize]
        else:
            proj_ksize = [kernel_size, kernel_size]

        strides = self._block_args.strides
        if self.stride_front:
            proj_strides = [1, 1]
        else:
            proj_strides = strides

        kwargs = dict(cls=Conv2D.__name__,
                      output_filters=output_filters,
                      kernel_size=proj_ksize,
                      strides=proj_strides)

        self._proj_layers = build_conv_bn_act(self._global_params,
                                              kwargs,
                                              add_bn=True,
                                              act_fn=None)
Esempio n. 9
0
 def _build_dwise(self, output_filters):
     kwargs = None
     self._dwise_layers = build_conv_bn_act(self._global_params, kwargs)
Esempio n. 10
0
 def _build_stem_layers(self, model_args):
     self._stem_layers = build_conv_bn_act(self._global_params,
                                           model_args.first_conv,
                                           add_bn=True,
                                           act_fn=self.act_fn)