import torch


def inference_single_frame(model, data, return_heatmap=False, beautify_results=True):
    """
    Does inference for model of a given a single data object.

    Arguments:
        model   MMDataParallel/nn.Module in eval mode
        data    dict(
                    img         torch.Tensor
                    img_metas   mmcv.DataContainer
                )
        return_heatmap      bool    decides if keypoint heatmaps shall be returned
        beautify_results    bool    decides if the vanilla return from mmpose should be used or if results will be beatified (human readable)

    Desc:
        'img_metas' DataContainer consists of
            [[
                dict(
                    image_file  str
                    center      np.ndarray of shape (2,)
                    scale       np.ndarray of shape (2,)
                    rotation    float
                    bbox_score  float
                    flip_pairs  list of list of ints of shape (16, 2)
                )
            ]]

    Returns:
        results     inference results, can be beautified as a dict or mmpose vanilla result format
    """
    with torch.no_grad():
        result = model(return_heatmap=return_heatmap, return_loss=False, **data)

    if not beautify_results:
        return result

    # beautify results
    results = dict(
        keypoints = result[0],
        unknown = result[1],
        image_file = "".join(result[2])
     )

    if return_heatmap:
        results['heatmap'] = result[3]

    return results