ultralytics / ultralytics

Ultralytics YOLO11 🚀
https://docs.ultralytics.com
GNU Affero General Public License v3.0
33.33k stars 6.41k forks source link

my confusion in rboxes 's range #8930

Closed feiwenxiong closed 7 months ago

feiwenxiong commented 8 months ago

Search before asking

Question

def regularize_rboxes(rboxes): """ Regularize rotated boxes in range [0, pi/2].

Args:
    rboxes (torch.Tensor): (N, 5), xywhr.

Returns:
    (torch.Tensor): The regularized boxes.
"""
x, y, w, h, t = rboxes.unbind(dim=-1)
# Swap edge and angle if h >= w
w_ = torch.where(w > h, w, h)
h_ = torch.where(w > h, h, w)
t = torch.where(w > h, t, t + math.pi / 2) % math.pi
return torch.stack([x, y, w_, h_, t], dim=-1)  # regularized boxes

Hi ,i am confused: since t is in [0 , pi / 2], and this function returns regularized boxes in range [0, pi/2] as stated in docString, how come " torch.where(w > h, t, t + math.pi / 2) % math.pi " ranges in [0, pi / 2]?

Additional

No response

github-actions[bot] commented 8 months ago

👋 Hello @feiwenxiong, thank you for your interest in Ultralytics YOLOv8 🚀! We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered.

If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Join the vibrant Ultralytics Discord 🎧 community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users.

Install

Pip install the ultralytics package including all requirements in a Python>=3.8 environment with PyTorch>=1.8.

pip install ultralytics

Environments

YOLOv8 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

Ultralytics CI

If this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

glenn-jocher commented 8 months ago

@feiwenxiong hey there! 😊 It's great that you're diving into the details of rotating bounding boxes (rboxes). Let's clarify the confusion around the angle t range.

The purpose of the regularize_rboxes function is to ensure that the longer side of the bounding box is always considered the width (w) and its angle t is adjusted accordingly to maintain consistency. This adjustment helps in standardizing the boxes for further processing.

When we swap w and h for cases where h > w, we also adjust the angle t by adding pi/2 to it. This is because we're essentially rotating the box by 90 degrees to keep the longer side as the width. The modulo operation % math.pi ensures that the angle stays within the range [0, pi].

However, you're right to notice that the comment and the function's docstring mention the range [0, pi/2], which seems to be a discrepancy since the actual range after regularization is [0, pi]. This is because after adding pi/2, the angle could indeed be in the range [pi/2, pi].

Here's a quick fix to align with the intended range [0, pi/2]:

t = (torch.where(w > h, t, t + math.pi / 2) + math.pi) % (math.pi / 2)

This adjustment ensures t is correctly wrapped within [0, pi/2] after regularization. However, note that this modification might not directly apply to your use case without additional context on how angles are interpreted in your application.

Thanks for pointing out this confusion, and I hope this clears things up! If you have more questions, feel free to ask.

feiwenxiong commented 8 months ago

Hi,got it, appreciate your patience and clear answer!

glenn-jocher commented 8 months ago

@feiwenxiong you're welcome! I'm glad the explanation was helpful. If you have more questions or need further assistance, don't hesitate to ask. Happy coding! 😊

github-actions[bot] commented 7 months ago

👋 Hello there! We wanted to give you a friendly reminder that this issue has not had any recent activity and may be closed soon, but don't worry - you can always reopen it if needed. If you still have any questions or concerns, please feel free to let us know how we can help.

For additional resources and information, please see the links below:

Feel free to inform us of any other issues you discover or feature requests that come to mind in the future. Pull Requests (PRs) are also always welcomed!

Thank you for your contributions to YOLO 🚀 and Vision AI ⭐