Пример #1
0
    def __init__(self,
                 in_channels,
                 out_channels,
                 strides,
                 use_kernel3,
                 exp_factor,
                 use_se,
                 bn_use_global_stats=False,
                 **kwargs):
        super(GhostUnit, self).__init__(**kwargs)
        self.resize_identity = (in_channels != out_channels) or (strides != 1)

        with self.name_scope():
            self.body = GhostExpBlock(in_channels=in_channels,
                                      out_channels=out_channels,
                                      strides=strides,
                                      use_kernel3=use_kernel3,
                                      exp_factor=exp_factor,
                                      use_se=use_se,
                                      bn_use_global_stats=bn_use_global_stats)
            if self.resize_identity:
                self.identity_conv = dwsconv3x3_block(
                    in_channels=in_channels,
                    out_channels=out_channels,
                    strides=strides,
                    bn_use_global_stats=bn_use_global_stats,
                    pw_activation=None)
Пример #2
0
    def __init__(self,
                 in_channels,
                 out_channels,
                 strides,
                 use_kernel3,
                 exp_factor,
                 use_se,
                 data_format="channels_last",
                 **kwargs):
        super(GhostUnit, self).__init__(**kwargs)
        self.resize_identity = (in_channels != out_channels) or (strides != 1)

        self.body = GhostExpBlock(in_channels=in_channels,
                                  out_channels=out_channels,
                                  strides=strides,
                                  use_kernel3=use_kernel3,
                                  exp_factor=exp_factor,
                                  use_se=use_se,
                                  data_format=data_format,
                                  name="body")
        if self.resize_identity:
            self.identity_conv = dwsconv3x3_block(in_channels=in_channels,
                                                  out_channels=out_channels,
                                                  strides=strides,
                                                  pw_activation=None,
                                                  data_format=data_format,
                                                  name="identity_conv")
 def __init__(self,
              in_channels,
              out_channels,
              data_format="channels_last",
              **kwargs):
     super(LwopEncoderFinalBlock, self).__init__(**kwargs)
     self.pre_conv = conv1x1_block(in_channels=in_channels,
                                   out_channels=out_channels,
                                   use_bias=True,
                                   use_bn=False,
                                   data_format=data_format,
                                   name="pre_conv")
     self.body = SimpleSequential(name="body")
     for i in range(3):
         self.body.add(
             dwsconv3x3_block(in_channels=out_channels,
                              out_channels=out_channels,
                              dw_use_bn=False,
                              pw_use_bn=False,
                              dw_activation=(lambda: nn.ELU()),
                              pw_activation=(lambda: nn.ELU()),
                              data_format=data_format,
                              name="block{}".format(i + 1)))
     self.post_conv = conv3x3_block(in_channels=out_channels,
                                    out_channels=out_channels,
                                    use_bias=True,
                                    use_bn=False,
                                    data_format=data_format,
                                    name="post_conv")
Пример #4
0
    def __init__(self,
                 channels,
                 first_stage_stride,
                 dw_use_bn=True,
                 dw_activation="relu",
                 in_channels=3,
                 in_size=(224, 224),
                 classes=1000,
                 data_format="channels_last",
                 **kwargs):
        super(MobileNet, self).__init__(**kwargs)
        self.in_size = in_size
        self.classes = classes
        self.data_format = data_format

        self.features = SimpleSequential(name="features")
        init_block_channels = channels[0][0]
        self.features.add(
            conv3x3_block(in_channels=in_channels,
                          out_channels=init_block_channels,
                          strides=2,
                          data_format=data_format,
                          name="init_block"))
        in_channels = init_block_channels
        for i, channels_per_stage in enumerate(channels[1:]):
            stage = SimpleSequential(name="stage{}".format(i + 1))
            for j, out_channels in enumerate(channels_per_stage):
                strides = 2 if (j == 0) and (
                    (i != 0) or first_stage_stride) else 1
                stage.add(
                    dwsconv3x3_block(in_channels=in_channels,
                                     out_channels=out_channels,
                                     strides=strides,
                                     dw_use_bn=dw_use_bn,
                                     dw_activation=dw_activation,
                                     data_format=data_format,
                                     name="unit{}".format(j + 1)))
                in_channels = out_channels
            self.features.add(stage)
        self.features.add(
            nn.AveragePooling2D(pool_size=7,
                                strides=1,
                                data_format=data_format,
                                name="final_pool"))

        self.output1 = nn.Dense(units=classes,
                                input_dim=in_channels,
                                name="output1")
    def __init__(self,
                 encoder_channels,
                 encoder_paddings,
                 encoder_init_block_channels,
                 encoder_final_block_channels,
                 refinement_units,
                 calc_3d_features,
                 return_heatmap=True,
                 in_channels=3,
                 in_size=(368, 368),
                 keypoints=19,
                 data_format="channels_last",
                 **kwargs):
        super(LwOpenPose, self).__init__(**kwargs)
        assert (in_channels == 3)
        self.in_size = in_size
        self.keypoints = keypoints
        self.data_format = data_format
        self.return_heatmap = return_heatmap
        self.calc_3d_features = calc_3d_features
        num_heatmap_paf = 3 * keypoints

        self.encoder = tf.keras.Sequential(name="encoder")
        backbone = SimpleSequential(name="backbone")
        backbone.add(
            conv3x3_block(in_channels=in_channels,
                          out_channels=encoder_init_block_channels,
                          strides=2,
                          data_format=data_format,
                          name="init_block"))
        in_channels = encoder_init_block_channels
        for i, channels_per_stage in enumerate(encoder_channels):
            stage = SimpleSequential(name="stage{}".format(i + 1))
            for j, out_channels in enumerate(channels_per_stage):
                strides = 2 if (j == 0) and (i != 0) else 1
                padding = encoder_paddings[i][j]
                stage.add(
                    dwsconv3x3_block(in_channels=in_channels,
                                     out_channels=out_channels,
                                     strides=strides,
                                     padding=padding,
                                     dilation=padding,
                                     data_format=data_format,
                                     name="unit{}".format(j + 1)))
                in_channels = out_channels
            backbone.add(stage)
        self.encoder.add(backbone)
        self.encoder.add(
            LwopEncoderFinalBlock(in_channels=in_channels,
                                  out_channels=encoder_final_block_channels,
                                  data_format=data_format,
                                  name="final_block"))
        in_channels = encoder_final_block_channels

        self.decoder = tf.keras.Sequential(name="decoder")
        self.decoder.add(
            LwopDecoderInitBlock(in_channels=in_channels,
                                 keypoints=keypoints,
                                 data_format=data_format,
                                 name="init_block"))
        in_channels = encoder_final_block_channels + num_heatmap_paf
        for i in range(refinement_units):
            self.decoder.add(
                LwopDecoderUnit(in_channels=in_channels,
                                keypoints=keypoints,
                                data_format=data_format,
                                name="unit{}".format(i + 1)))
        self.decoder.add(
            LwopDecoderFinalBlock(in_channels=in_channels,
                                  keypoints=keypoints,
                                  bottleneck_factor=2,
                                  calc_3d_features=calc_3d_features,
                                  data_format=data_format,
                                  name="final_block"))