//  [python]
def get_keypoint(image, predictions, heatmap_size, height, width, category, clip_at_zero=False, data_format='channels_last', name=None):
    # expand_border = 10
    # pad_pred = tf.pad(predictions, tf.constant([[0, 0], [0, 0], [expand_border, expand_border], [expand_border, expand_border]]),
    #               mode='CONSTANT', name='pred_padding', constant_values=0)

    # blur_pred = gaussian_blur(pad_pred, config.class_num_joints[category], 3.5, 'channels_first', 'pred_blur')

    # predictions = tf.slice(blur_pred, [0, 0, expand_border, expand_border], [1, config.class_num_joints[category], heatmap_size, heatmap_size])

    predictions = tf.reshape(predictions, [1, -1, heatmap_size*heatmap_size])

    pred_max = tf.reduce_max(predictions, axis=-1)
    pred_max_indices = tf.argmax(predictions, axis=-1)
    pred_max_x, pred_max_y = tf.to_float(tf.floormod(pred_max_indices, heatmap_size)), tf.to_float(tf.floordiv(pred_max_indices, heatmap_size))
    # mask the max elements to zero
    mask_predictions = predictions * tf.one_hot(pred_max_indices, heatmap_size*heatmap_size, on_value=0., off_value=1., dtype=tf.float32)
    # get the second max prediction
    pred_next_max = tf.reduce_max(mask_predictions, axis=-1)
    pred_next_max_indices = tf.argmax(mask_predictions, axis=-1)
    pred_next_max_x, pred_next_max_y = tf.to_float(tf.floormod(pred_next_max_indices, heatmap_size)), tf.to_float(tf.floordiv(pred_next_max_indices, heatmap_size))

    dist = tf.pow(tf.pow(pred_next_max_x - pred_max_x, 2.) + tf.pow(pred_next_max_y - pred_max_y, 2.), .5)

    pred_x = tf.where(dist < 1e-3, pred_max_x, pred_max_x + (pred_next_max_x - pred_max_x) * 0.25 / dist)
    pred_y = tf.where(dist < 1e-3, pred_max_y, pred_max_y + (pred_next_max_y - pred_max_y) * 0.25 / dist)

    pred_indices_ = tf.squeeze(tf.to_int64(pred_x) + tf.to_int64(pred_y) * heatmap_size)

    width, height = tf.to_float(width), tf.to_float(height)
    width_ratio, height_ratio = width / tf.to_float(heatmap_size), height / tf.to_float(heatmap_size)

    pred_x, pred_y = pred_x * width_ratio, pred_y * height_ratio
    #pred_x, pred_y = pred_x * width_ratio + width_ratio/2., pred_y * height_ratio + height_ratio/2.

    if clip_at_zero:
      pred_x, pred_y =  pred_x * tf.to_float(pred_max>0), pred_y * tf.to_float(pred_max>0)
      pred_x = pred_x * tf.to_float(pred_max>0) + tf.to_float(pred_max<=0) * (width / 2.)
      pred_y = pred_y * tf.to_float(pred_max>0) + tf.to_float(pred_max<=0) * (height / 2.)

    if config.PRED_DEBUG:
      image_ = tf.squeeze(image) * 255.
      pred_heatmap = tf.one_hot(pred_indices_, heatmap_size*heatmap_size, on_value=255, off_value=0, axis=-1, dtype=tf.int32)

      pred_heatmap = tf.reshape(pred_heatmap, [-1, heatmap_size, heatmap_size])
      if data_format == 'channels_first':
        image_ = tf.transpose(image_, perm=(1, 2, 0))
      save_image_op = tf.py_func(save_image_with_heatmap,
                                  [image_, height, width,
                                  heatmap_size,
                                  pred_heatmap,
                                  tf.reshape(predictions, [-1, heatmap_size, heatmap_size]),
                                  config.left_right_group_map[category][0],
                                  config.left_right_group_map[category][1],
                                  config.left_right_group_map[category][2]],
                                  tf.int64, stateful=True)
      with tf.control_dependencies([save_image_op]):
        pred_x, pred_y = pred_x * 1., pred_y * 1.
    return pred_x, pred_y