这是indexloc提供的服务,不要输入任何密码
Skip to content

About coords transforms in inference  #364

@bbnwang

Description

@bbnwang

hi, I find a issue in the inference. The coords postprocess use detector_postprocess. It just scale the coord by a factor of the input image size divide the output size. In my case, I do a crop first to crop out the invalid region. There is a offset between the ori image and the input one. The simple scale strategy is not work.

I try to solve this issue using the transforms.inverse() in the mapper.

import torch
import numpy as np
from detectron2.data import detection_utils as utils
from detectron2.structures import BoxMode, Boxes

def detector_postprocess(results_per_image, inverse_transform, ori_image_size):
    """warped transform_instance_annotations for detector_postprocess

    Args:
        results_per_image (instance): _description_
        reverse_transform (TransfromList): _description_
        ori_image_size (tuple): _description_
    """
    # xyxy
    pred_bboxes = results_per_image.pred_boxes.tensor.cpu().numpy()
    bbox_mode = BoxMode.XYXY_ABS
    pred_keypoints = results_per_image.pred_keypoints.cpu().numpy()
    
    bbox_list, keypoints_list = [], []
    for pred_box, pred_keypoint in zip(pred_bboxes, pred_keypoints):
        obj = {}
        obj['bbox'] = pred_box
        obj['bbox_mode'] = bbox_mode
        obj['keypoints'] = pred_keypoint
    
        obj_ = utils.transform_instance_annotations(obj, inverse_transform, ori_image_size)
        bbox_list.append(obj_['bbox'])
        keypoints_list.append(obj_['keypoints'])
    results_per_image.pred_boxes = Boxes(np.array(bbox_list))
    results_per_image.pred_keypoints = torch.from_numpy(np.array(keypoints_list))
    
    return results_per_image
    

I wonder if there is a more elegant way to solve this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions