Пример #1
0
    def feature2image(self, feature_tensor):

        output_channels = 3*self.recon_dist_param_num
        hgd = [
            {"type": "conv2d", "depth": 64, "decoder_depth": output_channels, "decoder_activation_fn": None},
            {"type": "conv2d", "depth": 64, "decoder_depth": 32},
            {"type": "skip", "layer_num": 2},
            {"type": "pool", "pool": "max", "kernel": 2, "stride": 2},  # 40 x 40
            {"type": "conv2d", "depth": 128, "decoder_depth": 64},
            {"type": "skip", "layer_num": 2},
            {"type": "pool", "pool": "max", "kernel": 2, "stride": 2},  # 20x20
            {"type": "conv2d", "depth": 256},
            {"type": "skip", "layer_num": 2},
            {"type": "pool", "pool": "max", "kernel": 2, "stride": 2},  # 10x10
            {"type": "conv2d", "depth": 512},
            {"type": "skip", "layer_num": 2},
            {"type": "pool", "pool": "max", "kernel": 2, "stride": 2},  # 5x5
            {"type": "conv2d", "depth": 512},
        ]

        with pt.defaults_scope(**self.pt_defaults_scope_value()):
            output_tensor = hourglass(
                feature_tensor, hgd,
                net_type=self.options["hourglass_type"] if "hourglass_type" in self.options else None,
                extra_highlevel_feature=None
            )

        return output_tensor
    def image2feature(self, image_tensor):

        if self.patch_feature_dim == 0:
            return None

        mid_tensor = (
            pt.wrap(image_tensor).
            conv2d(3, 32).
            max_pool(2, 2)
        ).tensor  # 64x64

        hgd = [
            {"type": "conv2d", "depth": 64},
            {"type": "skip", "layer_num": 2},
            {"type": "pool", "pool": "max", "kernel": 2, "stride": 2},  # 32 x 32
            {"type": "conv2d", "depth": 128},
            {"type": "skip", "layer_num": 2},
            {"type": "pool", "pool": "max", "kernel": 2, "stride": 2},  # 16 x 16
            {"type": "conv2d", "depth": 256},
            {"type": "skip", "layer_num": 2},
            {"type": "pool", "pool": "max", "kernel": 2, "stride": 2},  # 8 x 8
            {"type": "conv2d", "depth": 512},
            {"type": "skip", "layer_num": 2},
            {"type": "pool", "pool": "max", "kernel": 2, "stride": 2},  # 4 x 4
            {"type": "conv2d", "depth": 512},
        ]

        with pt.defaults_scope(**self.pt_defaults_scope_value()):
            feature_map = hourglass(
                mid_tensor, hgd,
                net_type=self.options["hourglass_type"] if "hourglass_type" in self.options else None
            )

        return feature_map
Пример #3
0
def encoder_map(input_tensor, hourglass_type=None):

    hgd = [
        {
            "type": "conv2d",
            "depth": 32,
            "decoder_depth": 64
        },
        {
            "type": "conv2d",
            "depth": 64,
            "decoder_depth": 64
        },
        {
            "type": "skip",
            "layer_num": 2
        },
        {
            "type": "pool",
            "pool": "max",
            "kernel": 2,
            "stride": 2
        },  # 40 x 40
        {
            "type": "conv2d",
            "depth": 128
        },
        {
            "type": "skip",
            "layer_num": 2
        },
        {
            "type": "pool",
            "pool": "max",
            "kernel": 2,
            "stride": 2
        },  # 20x20
        {
            "type": "conv2d",
            "depth": 256
        },
        {
            "type": "skip",
            "layer_num": 2
        },
        {
            "type": "pool",
            "pool": "max",
            "kernel": 2,
            "stride": 2
        },  # 10x10
        {
            "type": "conv2d",
            "depth": 512
        },
    ]

    output_tensor = hourglass(input_tensor, hgd, net_type=hourglass_type)
    return output_tensor
Пример #4
0
    def image2heatmap(self, image_tensor):
        hgd = [
            {
                "type": "conv2d",
                "depth": 32,
                "decoder_depth": self.options["keypoint_num"] + 1,
                "decoder_activation_fn": None
            },
            # plus one for bg
            {
                "type": "conv2d",
                "depth": 32
            },
            {
                "type": "skip",
                "layer_num": 3,
            },
            {
                "type": "pool",
                "pool": "max"
            },
            {
                "type": "conv2d",
                "depth": 64
            },
            {
                "type": "conv2d",
                "depth": 64
            },
            {
                "type": "skip",
                "layer_num": 3,
            },
            {
                "type": "pool",
                "pool": "max"
            },
            {
                "type": "conv2d",
                "depth": 64
            },
            {
                "type": "conv2d",
                "depth": 64
            },
            {
                "type": "skip",
                "layer_num": 3,
            },
            {
                "type": "pool",
                "pool": "max"
            },
            {
                "type": "conv2d",
                "depth": 64
            },
            {
                "type": "conv2d",
                "depth": 64
            },
        ]

        with pt.defaults_scope(**self.pt_defaults_scope_value()):
            raw_heatmap = hourglass(image_tensor,
                                    hgd,
                                    net_type=self.options["hourglass_type"] if
                                    "hourglass_type" in self.options else None)
            # raw_heatmap = pt.wrap(raw_heatmap).pixel_bias(activation_fn=None).tensor

        return raw_heatmap
Пример #5
0
    def image2feature(self, image_tensor):

        if self.patch_feature_dim == 0:
            return None

        hgd = [
            {
                "type": "conv2d",
                "depth": 32,
                "decoder_depth": 64
            },
            {
                "type": "conv2d",
                "depth": 64,
                "decoder_depth": 64
            },
            {
                "type": "skip",
                "layer_num": 2
            },
            {
                "type": "pool",
                "pool": "max",
                "kernel": 2,
                "stride": 2
            },  # 40 x 40
            {
                "type": "conv2d",
                "depth": 128
            },
            {
                "type": "skip",
                "layer_num": 2
            },
            {
                "type": "pool",
                "pool": "max",
                "kernel": 2,
                "stride": 2
            },  # 20x20
            {
                "type": "conv2d",
                "depth": 256
            },
            {
                "type": "skip",
                "layer_num": 2
            },
            {
                "type": "pool",
                "pool": "max",
                "kernel": 2,
                "stride": 2
            },  # 10x10
            {
                "type": "conv2d",
                "depth": 512
            },
        ]

        with pt.defaults_scope(**self.pt_defaults_scope_value()):
            feature_map = hourglass(image_tensor,
                                    hgd,
                                    net_type=self.options["hourglass_type"] if
                                    "hourglass_type" in self.options else None)
        return feature_map
Пример #6
0
 def feature2image(self, feature_map):
     output_channels = 3 * self.recon_dist_param_num
     hgd = [
         {
             "type": "conv2d",
             "depth": 64
         },
         {
             "type": "skip",
             "layer_num": 2
         },
         {
             "type": "pool",
             "pool": "max",
             "kernel": 2,
             "stride": 2
         },  # 32x32
         {
             "type": "conv2d",
             "depth": 128
         },
         {
             "type": "skip",
             "layer_num": 2
         },
         {
             "type": "pool",
             "pool": "max",
             "kernel": 2,
             "stride": 2
         },  # 16x16
         {
             "type": "conv2d",
             "depth": 256
         },
         {
             "type": "skip",
             "layer_num": 2
         },
         {
             "type": "pool",
             "pool": "max",
             "kernel": 2,
             "stride": 2
         },  # 8x8
         {
             "type": "conv2d",
             "depth": 512
         },
         {
             "type": "skip",
             "layer_num": 2
         },
         {
             "type": "pool",
             "pool": "max",
             "kernel": 2,
             "stride": 2
         },  # 4x4
         {
             "type": "conv2d",
             "depth": 512
         },
     ]
     with pt.defaults_scope(**self.pt_defaults_scope_value()):
         output_tensor = hourglass(
             feature_map,
             hgd,
             net_type=self.options["hourglass_type"]
             if "hourglass_type" in self.options else None,
             extra_highlevel_feature=None)
         output_tensor = (pt.wrap(output_tensor).deconv2d(
             3, 32, stride=2).conv2d(3, output_channels,
                                     activation_fn=None)).tensor
     return output_tensor