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

[Feature] Support RBox CopyPaste #877

Open
wants to merge 4 commits into
base: dev-1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions configs/h2rbox/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ DOTA2.0

DIOR

| Backbone | AP50:95 | AP50 | AP75 | Angle | lr schd | Mem (GB) | Inf Time (fps) | MS | Batch Size | Configs | Download |
| :----------------------: | :-----: | :---: | :---: | :---: | :-----: | :------: | :------------: | :-: | :--------: | :------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| ResNet50 (800,800) | 33.06 | 57.40 | 32.50 | le90 | 1x | 3.83 | | - | 2 | [h2rbox-le90_r50_fpn_adamw-1x_dior](./dior/h2rbox-le90_r50_fpn_adamw-1x_dior.py) | [model](https://download.openmmlab.com/mmrotate/v1.0/h2rbox/h2rbox-le90_r50_fpn_adamw-1x_dior/h2rbox-le90_r50_fpn_adamw-1x_dior-949b0e4c.pth) \| [log](https://download.openmmlab.com/mmrotate/v1.0/h2rbox/h2rbox-le90_r50_fpn_adamw-1x_dior/h2rbox-le90_r50_fpn_adamw-1x_dior-20221130_204038.json) |
| Backbone | AP50:95 | AP50 | AP75 | Angle | lr schd | Mem (GB) | Inf Time (fps) | MS | Batch Size | Configs | Download |
| :----------------: | :-----: | :---: | :---: | :---: | :-----: | :------: | :------------: | :-: | :--------: | :------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: |
| ResNet50 (800,800) | 33.06 | 57.40 | 32.50 | le90 | 1x | 3.83 | | - | 2 | [h2rbox-le90_r50_fpn_adamw-1x_dior](./dior/h2rbox-le90_r50_fpn_adamw-1x_dior.py) | [model](https://download.openmmlab.com/mmrotate/v1.0/h2rbox/h2rbox-le90_r50_fpn_adamw-1x_dior/h2rbox-le90_r50_fpn_adamw-1x_dior-949b0e4c.pth) \| [log](https://download.openmmlab.com/mmrotate/v1.0/h2rbox/h2rbox-le90_r50_fpn_adamw-1x_dior/h2rbox-le90_r50_fpn_adamw-1x_dior-20221130_204038.json) |

**Notes:**

Expand Down
16 changes: 16 additions & 0 deletions mmrotate/structures/bbox/quadri_boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,22 @@ def find_inside_points(self,
values = (x1 - pt_x) * (y2 - pt_y) - (y1 - pt_y) * (x2 - pt_x)
return (values >= eps).all(dim=-1) | (values <= -eps).all(dim=-1)

def create_masks(self, img_shape: Tuple[int, int]) -> BitmapMasks:
"""
Args:
img_shape (Tuple[int, int]): A tuple of image height and width.
Returns:
:obj:`BitmapMasks`: Converted masks
"""
img_h, img_w = img_shape
polygons = self.vertices.numpy().astype(np.int0)

gt_masks = np.zeros((len(polygons), img_h, img_w), dtype=np.uint8)

for i, polygon in enumerate(polygons):
cv2.drawContours(gt_masks[i], [polygon], 0, 1, -1)
return BitmapMasks(gt_masks, img_h, img_w)

@staticmethod
def overlaps(boxes1: BaseBoxes,
boxes2: BaseBoxes,
Expand Down
13 changes: 12 additions & 1 deletion mmrotate/structures/bbox/rotated_boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,16 @@ def find_inside_points(self,
return (offset_x <= w / 2 - eps) & (offset_x >= - w / 2 + eps) & \
(offset_y <= h / 2 - eps) & (offset_y >= - h / 2 + eps)

def create_masks(self, img_shape: Tuple[int, int]) -> BitmapMasks:
"""
Args:
img_shape (Tuple[int, int]): A tuple of image height and width.
Returns:
:obj:`BitmapMasks`: Converted masks
"""
qbox = self.convert_to('qbox')
return qbox.create_masks(img_shape)

@staticmethod
def overlaps(boxes1: BaseBoxes,
boxes2: BaseBoxes,
Expand Down Expand Up @@ -442,7 +452,8 @@ def from_instance_masks(masks: MaskType) -> 'RotatedBoxes':
if isinstance(masks, BitmapMasks):
for idx in range(num_masks):
mask = masks.masks[idx]
points = np.stack(np.nonzero(mask), axis=-1).astype(np.float32)
coor_y, coor_x = np.nonzero(mask)
points = np.stack([coor_x, coor_y], axis=-1).astype(np.float32)
(x, y), (w, h), angle = cv2.minAreaRect(points)
boxes.append([x, y, w, h, angle / 180 * np.pi])
elif isinstance(masks, PolygonMasks):
Expand Down