# Path: net_modules/keypoints_2d.py
# def yx_grid_map(h, w, dtype, aspect_ratio=1.):
# def keypoint_map_to_gaussian_coordinate(keypoint_map, diag_cov=None, use_hard_max_as_anchors=None):
#     def cyclic_clip(a):
# def gaussian_coordinate_to_keypoint_map(yx_mean_stddev_corr, km_h, km_w, dtype=None):
# def gaussian2dparam_to_real(p):
# def real_to_gaussian2dparam(r):
# def gaussian2dparam_to_recon_code(p):
# def real_to_recon_code(r):
# def gaussian2d_det(p, no_mean_input=False):
# def gaussian2d_entropy(p, no_mean_input=False):
# def gaussian2d_exp_entropy(p, no_mean_input=False, stddev_scaling=1.):
# def gaussian2d_axis_balancing(p, no_mean_input=False):
# def keypoint_map_boundary_mask(h, w, padding_h, padding_w, dtype=np.float32):
# def keypoint_map_boundary_mask_with_bg(h, w, padding_h, padding_w, keypoint_num, dtype=np.float32):
# def keypoint_map_depth_normalization_with_fake_bg(keypoint_map):
# def keypoint_map_depth_entropy_with_fake_bg(keypoint_map):
# def keypoint_map_depth_normalization_with_real_bg(keypoint_map):
# def keypoint_map_depth_entropy_with_real_bg(keypoint_map):
# def scale_keypoint_param(keypoint_param, scaling_factor, src_aspect_ratio):
# def get_map_aspect_ratio(a):
# def parse_landmark_condition_tensor_single(condition_tensor, img_size=None, full_img_size=None):
# def parse_landmark_condition_struct(keypoint_struct, img_size=None, full_img_size=None):
# 
# Path: net_modules/distribution_utils.py
# def reshape_extended_features(a, param_factor):
#     if a is None:
#         return None, None
#     kept_shape = tmf.get_shape(a)[:-1] + [tmf.get_shape(a)[-1] // param_factor]
#     a = tf.reshape(a, kept_shape + [param_factor])
#     main_chooser = (slice(None, None),) * len(kept_shape) + (0,)
#     b = a[main_chooser]
#     return a, b


from abc import ABCMeta, abstractmethod
from net_modules import keypoints_2d
from net_modules.distribution_utils import reshape_extended_features
from zutils.py_utils import *
import tensorflow as tf
import prettytensor as pt
import zutils.tf_math_funcs as tmf
import net_modules.auto_struct.utils as asu
import zutils.pt_utils as ptu
import numpy as np
            self.patch_feature_dim = self.options["overall_feature_dim"]

    def __call__(self, input_tensor, condition_tensor=None, extra_inputs=None):
        im, _, mos = self.decode(input_tensor, condition_tensor=condition_tensor, extra_inputs=extra_inputs)
        return im, mos.extra_outputs

    def decode(self, input_tensor, condition_tensor=None, extra_inputs=None):
        """Create encoder network.
        """

        if extra_inputs is None:
            extra_inputs = dict()

        assert self.structure_param_num is not None, "structure_param_num is not defined"

        # module output strip
        mos = asu.ModuleOutputStrip()

        with tf.variable_scope("variational"):
            # latent to structure, patch, and overall
            structure_param_x, patch_features_x, overall_features_x = mos(
                self._latent2structure_patch_overall(latent_tensor=input_tensor))

            structure_param_x = mos(self.structure_postprocess(structure_param_x))

            actual_structure_param_num = tmf.get_shape(structure_param_x)[-1]
            the_param_factor = (actual_structure_param_num // self.structure_param_num)
            assert the_param_factor == self.feature_extended_num, "wrong dim for feature extension"
            structure_param_x, structure_param = reshape_extended_features(structure_param_x, the_param_factor)
            patch_features_x, patch_features = reshape_extended_features(patch_features_x, the_param_factor)

# Path: net_modules/keypoints_2d.py
# def yx_grid_map(h, w, dtype, aspect_ratio=1.):
# def keypoint_map_to_gaussian_coordinate(keypoint_map, diag_cov=None, use_hard_max_as_anchors=None):
#     def cyclic_clip(a):
# def gaussian_coordinate_to_keypoint_map(yx_mean_stddev_corr, km_h, km_w, dtype=None):
# def gaussian2dparam_to_real(p):
# def real_to_gaussian2dparam(r):
# def gaussian2dparam_to_recon_code(p):
# def real_to_recon_code(r):
# def gaussian2d_det(p, no_mean_input=False):
# def gaussian2d_entropy(p, no_mean_input=False):
# def gaussian2d_exp_entropy(p, no_mean_input=False, stddev_scaling=1.):
# def gaussian2d_axis_balancing(p, no_mean_input=False):
# def keypoint_map_boundary_mask(h, w, padding_h, padding_w, dtype=np.float32):
# def keypoint_map_boundary_mask_with_bg(h, w, padding_h, padding_w, keypoint_num, dtype=np.float32):
# def keypoint_map_depth_normalization_with_fake_bg(keypoint_map):
# def keypoint_map_depth_entropy_with_fake_bg(keypoint_map):
# def keypoint_map_depth_normalization_with_real_bg(keypoint_map):
# def keypoint_map_depth_entropy_with_real_bg(keypoint_map):
# def scale_keypoint_param(keypoint_param, scaling_factor, src_aspect_ratio):
# def get_map_aspect_ratio(a):
# def parse_landmark_condition_tensor_single(condition_tensor, img_size=None, full_img_size=None):
# def parse_landmark_condition_struct(keypoint_struct, img_size=None, full_img_size=None):
# 
# Path: net_modules/distribution_utils.py
# def reshape_extended_features(a, param_factor):
#     if a is None:
#         return None, None
#     kept_shape = tmf.get_shape(a)[:-1] + [tmf.get_shape(a)[-1] // param_factor]
#     a = tf.reshape(a, kept_shape + [param_factor])
#     main_chooser = (slice(None, None),) * len(kept_shape) + (0,)
#     b = a[main_chooser]
#     return a, b


# Path: net_modules/auto_struct/generic_decoder.py
from abc import ABCMeta, abstractmethod
from net_modules import keypoints_2d
from net_modules.distribution_utils import reshape_extended_features
from zutils.py_utils import *
import tensorflow as tf
import prettytensor as pt
import zutils.tf_math_funcs as tmf
import net_modules.auto_struct.utils as asu
import zutils.pt_utils as ptu
import numpy as np

            self.patch_feature_dim = self.options["overall_feature_dim"]

    def __call__(self, input_tensor, condition_tensor=None, extra_inputs=None):
        im, _, mos = self.decode(input_tensor, condition_tensor=condition_tensor, extra_inputs=extra_inputs)
        return im, mos.extra_outputs

    def decode(self, input_tensor, condition_tensor=None, extra_inputs=None):
        """Create encoder network.
        """

        if extra_inputs is None:
            extra_inputs = dict()

        assert self.structure_param_num is not None, "structure_param_num is not defined"

        # module output strip
        mos = asu.ModuleOutputStrip()

        with tf.variable_scope("variational"):
            # latent to structure, patch, and overall
            structure_param_x, patch_features_x, overall_features_x = mos(
                self._latent2structure_patch_overall(latent_tensor=input_tensor))

            structure_param_x = mos(self.structure_postprocess(structure_param_x))

            actual_structure_param_num = tmf.get_shape(structure_param_x)[-1]
            the_param_factor = (actual_structure_param_num // self.structure_param_num)
            assert the_param_factor == self.feature_extended_num, "wrong dim for feature extension"
            structure_param_x, structure_param = reshape_extended_features(structure_param_x, the_param_factor)
            patch_features_x, patch_features = reshape_extended_features(patch_features_x, the_param_factor)

            overall_features_x, overall_features = reshape_extended_features(overall_features_x, the_param_factor)