Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About coords transforms in inference #364

Open
bbnwang opened this issue Oct 29, 2024 · 0 comments
Open

About coords transforms in inference #364

bbnwang opened this issue Oct 29, 2024 · 0 comments

Comments

@bbnwang
Copy link

bbnwang commented Oct 29, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant