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

Centerpoint bbox coders: Fix torch warning #2873

Open
wants to merge 3 commits into
base: dev-1.x
Choose a base branch
from

Conversation

chbehrens
Copy link

Motivation

I currently get the following warning from the centerpoints bbox coder:

mmdet3d/models/task_modules/coders/centerpoint_bbox_coders.py:207: UserWarning: To copy construct from a tensor, it is recommended to use sourceTensor.clone().detach() or sourceTensor.clone().detach().requires_grad_(True), rather than torch.tensor(sourceTensor).
  self.post_center_range = torch.tensor(

The reason is that self.post_center_range is already a torch.Tensor after the first call of decode and then torch.Tensor is called on a Tensor in every following call.

Modification

Create self.post_center_range as Tensor in the initialization of CenterPointBBoxCoder and only make sure that it is on the right device when decode is called.

BC-breaking (Optional)

Does the modification introduce changes that break the back-compatibility of the downstream repos?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.
No breaking/functionally relevant changes

Use cases (Optional)

If this PR introduces a new feature, it is better to list some use cases here, and update the documentation.

Checklist

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  3. If the modification has potential influence on downstream projects, this PR should be tested with downstream projects.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@@ -36,7 +36,7 @@ def __init__(self,
self.pc_range = pc_range
self.out_size_factor = out_size_factor
self.voxel_size = voxel_size
self.post_center_range = post_center_range
self.post_center_range = Tensor(post_center_range)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should notice that the default post_center_range is None, which may cause an error here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, I updated it so that it stays None in that case.

@chbehrens
Copy link
Author

chbehrens commented Jan 15, 2024

I added another small commit to fix the type annotation for vel in the decode function as it can be None as well as the dimensions of the dim and vel tensors in the docstring.

@Tai-Wang Tai-Wang changed the base branch from main to dev-1.x January 17, 2024 08:25
@chbehrens
Copy link
Author

Could someone please retrigger the pipelines that got stuck so this can get merged?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants