mmrotate
mmrotate copied to clipboard
[Bug] v1.x image_demo bboxes AttributeError: 'Tensor' object has no attribute 'convert_to'
Prerequisite
- [X] I have searched Issues and Discussions but cannot get the expected help.
- [X] I have read the FAQ documentation but cannot get the expected help.
- [X] The bug has not been fixed in the latest version (master) or latest version (1.x).
Task
I'm using the official example scripts/configs for the officially supported tasks/models/datasets.
Branch
1.x branch https://github.com/open-mmlab/mmrotate/tree/1.x
Environment
Not found in dev-1.x: python: can't open file 'mmrotate/utils/collect_env.py': [Errno 2] No such file or directory
Reproduces the problem - code sample
I trained the Oriented R-CNN model on the tiny SSDD example dataset for 3 epochs. I'm now attempting to run demo/image_demo.py on an image from the dataset (ssdd_tiny/images/000631.png), but get an error with the bboxes.
Reproduces the problem - command or script
python demo/image_demo.py ssdd_tiny/images/000631.png <config path> <checkpoint path> --out-file result.jpg
Reproduces the problem - error message
local loads checkpoint from path: /opt/ml/model/epoch_12.pth
The model and loaded state dict do not match exactly
size mismatch for roi_head.bbox_head.fc_cls.weight: copying a param with shape torch.Size([2, 1024]) from checkpoint, the shape in current model is torch.Size([16, 1024]).
size mismatch for roi_head.bbox_head.fc_cls.bias: copying a param with shape torch.Size([2]) from checkpoint, the shape in current model is torch.Size([16]).
/opt/conda/lib/python3.8/site-packages/mmengine/visualization/visualizer.py:170: UserWarning: `Visualizer` backend is not initialized because save_dir is None.
warnings.warn('`Visualizer` backend is not initialized '
Traceback (most recent call last):
File "/opt/mmrotate/demo/image_demo.py", line 63, in <module>
main(args)
File "/opt/mmrotate/demo/image_demo.py", line 50, in main
visualizer.add_datasample(
File "/opt/conda/lib/python3.8/site-packages/mmengine/dist/utils.py", line 346, in wrapper
return func(*args, **kwargs)
File "/opt/mmdetection/mmdet/visualization/local_visualizer.py", line 368, in add_datasample
pred_img_data = self._draw_instances(image, pred_instances,
File "/opt/mmrotate/mmrotate/visualization/local_visualizer.py", line 73, in _draw_instances
polygons = bboxes.convert_to('qbox').tensor
AttributeError: 'Tensor' object has no attribute 'convert_to'
Additional information
No response
I encountered the same problem. Someone explained that mmrotate has rewritten the previous bbox writing method in order to access mmdet. It used to be a tensor, but now it continues to use the box list in mmdet. But I don't know how to solve it
In 1.x, the model output should be RotatedBoxes, maybe in local_visualizer we should add a type check.
maybe you try replace this line to:
polygon = rbox2qbox(bboxes)
@zytx121 should we add a check to handle tensor bboxes?
@liuyanyi Ah okay, yeah I'm using 1.x and it seems to be type Tensor for me 🤔
@liuyanyi Thank you for your help. Yes, I did. But there are new problems here. I may need to understand them comprehensively
File "G:/Scientific_Research/mmrotate-1.0.0rc0/tools/my_test.py", line 130, in
Hi @austinmw @jsago Sorry, it is a bug. and you can replace https://github.com/open-mmlab/mmrotate/blob/766185ed317f99379cb14035a6f9e5cf8a5340ad/mmrotate/visualization/local_visualizer.py#L72 with
from mmrotate.structures.bbox import RotatedBoxes
bboxes = RotatedBoxes(bboxes)
polygons = bboxes.convert_to('qbox').tensor
temporarily, or refer to #613.
In mmrotate 1.x, we use the BoxType to replace Torch.Tensor. We will provide detailed documentation about it later.

Now, you can refer unit test to learn how to use it. https://github.com/open-mmlab/mmrotate/tree/dev-1.x/tests/test_structures/test_bbox
Thank you very much for your feedback, which is very important to us ❤️❤️
Closing since this bug fixed, although when running demo I end up with a subsequent bug referenced in above merged PR