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

Fix image_demo bug. #613

Merged
merged 2 commits into from
Nov 15, 2022
Merged
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
14 changes: 13 additions & 1 deletion mmrotate/visualization/local_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
from mmdet.visualization import DetLocalVisualizer, jitter_color
from mmdet.visualization.palette import _get_adaptive_scales
from mmengine.structures import InstanceData
from torch import Tensor

from mmrotate.registry import VISUALIZERS
from mmrotate.structures.bbox import QuadriBoxes, RotatedBoxes
from .palette import get_palette


Expand Down Expand Up @@ -68,7 +70,17 @@ def _draw_instances(self, image: np.ndarray, instances: ['InstanceData'],
bbox_palette = get_palette(bbox_color, max_label + 1)
colors = [bbox_palette[label] for label in labels]

# convert to qbox
if isinstance(bboxes, Tensor):
if bboxes.size(-1) == 5:
bboxes = RotatedBoxes(bboxes)
elif bboxes.size(-1) == 8:
bboxes = QuadriBoxes(bboxes)
else:
raise TypeError(
'Require the shape of `bboxes` to be (n, 5) '
'or (n, 8), but get `bboxes` with shape being '
f'{bboxes.shape}.')

polygons = bboxes.convert_to('qbox').tensor
polygons = polygons.reshape(-1, 4, 2).numpy()
polygons = [p for p in polygons]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_visualization/test_local_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_add_datasample(self):

# test gt_instances
gt_instances = InstanceData()
gt_instances.bboxes = RotatedBoxes(_rand_rbboxes(num_bboxes, h, w))
gt_instances.bboxes = _rand_rbboxes(num_bboxes, h, w)
gt_instances.masks = _fake_masks(num_bboxes, h, w)
gt_instances.labels = torch.randint(0, num_class, (num_bboxes, ))
det_data_sample = DetDataSample()
Expand Down