-
Notifications
You must be signed in to change notification settings - Fork 230
Open
Description
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
Labels
No labels