You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Dear all,
I'm now running this code https://github.com/open-mmlab/mmrotate/blob/main/demo/huge_image_demo.py.
This code can inference huge image, it'll process huge image into several patches, and inference by patch, finally merge the labels in one.
And the main function of merging labels is FUNC. merge_results()
I am wondering that what does the **merge_results ** function do in MMrotate inference_detector_by_patches api.
As my understanding, it's the function merging labels from several patches.
I'm curious about what's the mind set to merge all labels in one? Is there any labels missing risk during merging?
Args:
results (list[np.ndarray] | list[tuple]): A list of patches results.
offsets (np.ndarray): Positions of the left top points of patches.
img_shape (tuple): A tuple of the huge image's width and height.
iou_thr (float): The IoU threshold of NMS.
device (str): The device to call nms.
Retunrns:
list[np.ndarray]: Detection results after merging.
"""
assert len(results) == offsets.shape[0], 'The `results` should has the ' \
'same length with `offsets`.'
with_mask = isinstance(results[0], tuple)
num_patches = len(results)
num_classes = len(results[0][0]) if with_mask else len(results[0])
merged_bboxes = []
merged_masks = []
for cls in range(num_classes):
if with_mask:
dets_per_cls = [results[i][0][cls] for i in range(num_patches)]
masks_per_cls = [results[i][1][cls] for i in range(num_patches)]
else:
dets_per_cls = [results[i][cls] for i in range(num_patches)]
masks_per_cls = None
dets_per_cls = [
translate_bboxes(dets_per_cls[i], offsets[i])
for i in range(num_patches)
]
dets_per_cls = np.concatenate(dets_per_cls, axis=0)
if with_mask:
masks_placeholder = []
for i, masks in enumerate(masks_per_cls):
translated = map_masks(masks, offsets[i], img_shape)
masks_placeholder.extend(translated)
masks_per_cls = masks_placeholder
if dets_per_cls.size == 0:
merged_bboxes.append(dets_per_cls)
if with_mask:
merged_masks.append(masks_per_cls)
else:
dets_per_cls = torch.from_numpy(dets_per_cls).to(device)
nms_func = nms if dets_per_cls.size(1) == 5 else nms_rotated
nms_dets, keeps = nms_func(dets_per_cls[:, :-1],
dets_per_cls[:, -1], iou_thr)
merged_bboxes.append(nms_dets.cpu().numpy())
if with_mask:
keeps = keeps.cpu().numpy()
merged_masks.append([masks_per_cls[i] for i in keeps])
if with_mask:
return merged_bboxes, merged_masks
else:
return merged_bboxes
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Dear all,
I'm now running this code https://github.com/open-mmlab/mmrotate/blob/main/demo/huge_image_demo.py.
This code can inference huge image, it'll process huge image into several patches, and inference by patch, finally merge the labels in one.
And the main function of merging labels is FUNC. merge_results()
I am wondering that what does the **merge_results ** function do in MMrotate inference_detector_by_patches api.
As my understanding, it's the function merging labels from several patches.
I'm curious about what's the mind set to merge all labels in one?
Is there any labels missing risk during merging?
Any ideas would help, thank you.
我現在在跑這隻程式 https://github.com/open-mmlab/mmrotate/blob/main/demo/huge_image_demo.py.
他可以在模型推理時,輸入大圖片給模型,並將大圖片分批預測,最後融合子批中的所有標籤,完成大圖片推理。
融合標籤主要是在merge_results 這個函式當中完成。
好奇想問merge_results 這個函式是怎麼做到標籤融合的?
在融合的過程中,會不會有標籤缺失的情況發生?
def merge_results(results, offsets, img_shape, iou_thr=0.1, device='cpu'):
"""Merge patch results via nms.
Beta Was this translation helpful? Give feedback.
All reactions