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

Anchors are not centered on grid cells #7951

Open
luukbalkenende opened this issue Jul 25, 2024 · 1 comment
Open

Anchors are not centered on grid cells #7951

luukbalkenende opened this issue Jul 25, 2024 · 1 comment
Labels

Comments

@luukbalkenende
Copy link

Describe the bug
Anchors should be placed ideally in the middle of a grid cell.
However, this is not the case here:

# compute anchor centers regarding to the image.
# shifts_centers is [x_center, y_center] or [x_center, y_center, z_center]
shifts_centers = [
torch.arange(0, size[axis], dtype=torch.int32, device=device) * stride[axis]
for axis in range(self.spatial_dims)
]

Expected behavior
The anchors should be placed ideally in the middle of a grid cell.

Possible fix
This could probably be fixed by simply changing these lines to:

shifts_centers = [
    torch.arange(0, size[axis], dtype=torch.int32, device=device) * stride[axis] + int(stride[axis] / 2)
    for axis in range(self.spatial_dims)
]
@1lyvianis
Copy link

Hi!

I think your idea of using int(stride[axis] / 2) is a great approach. However, I’m wondering if it might be better to use int(stride[axis] / 2 + 0.5) instead, to account for the fractional part that gets truncated by int(). What are your thoughts on this adjustment?

btw both methods would cause mismatch elements when running the test cases in test_anchor_box.py.

@KumoLiu KumoLiu added enhancement New feature or request Contribution wanted labels Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants