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

How to get pred box coordinates in loss.py? #7953

Closed
1 task done
HongYg opened this issue May 24, 2022 · 3 comments
Closed
1 task done

How to get pred box coordinates in loss.py? #7953

HongYg opened this issue May 24, 2022 · 3 comments
Labels
question Further information is requested Stale

Comments

@HongYg
Copy link

HongYg commented May 24, 2022

Search before asking

Question

Hi!
I want to get pred box coordinates in loss.py (x1,y1,y2,y2)

I'm having trouble analyzing it.
What's the solution?

thanks!

Additional

No response

@HongYg HongYg added the question Further information is requested label May 24, 2022
@glenn-jocher
Copy link
Member

glenn-jocher commented May 24, 2022

@HongYg box coordinates are not constructed in loss.py, only the minimum deltas (pred-truth) in gridspace are used there. The closest is this:

yolov5/utils/loss.py

Lines 137 to 143 in 27911dc

# Regression
pxy = pxy.sigmoid() * 2 - 0.5
pwh = (pwh.sigmoid() * 2) ** 2 * anchors[i]
pbox = torch.cat((pxy, pwh), 1) # predicted box
iou = bbox_iou(pbox, tbox[i], CIoU=True).squeeze() # iou(prediction, target)
lbox += (1.0 - iou).mean() # iou loss

@github-actions
Copy link
Contributor

github-actions bot commented Jun 24, 2022

👋 Hello, this issue has been automatically marked as stale because it has not had recent activity. Please note it will be closed if no further activity occurs.

Access additional YOLOv5 🚀 resources:

Access additional Ultralytics ⚡ resources:

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 YOLOv5 🚀 and Vision AI ⭐!

@mullenba
Copy link

mullenba commented Oct 12, 2022

@HongYg box coordinates are not constructed in loss.py, only the minimum deltas (pred-truth) in gridspace are used there. The closest is this:

yolov5/utils/loss.py

Lines 137 to 143 in 27911dc

# Regression
pxy = pxy.sigmoid() * 2 - 0.5
pwh = (pwh.sigmoid() * 2) ** 2 * anchors[i]
pbox = torch.cat((pxy, pwh), 1) # predicted box
iou = bbox_iou(pbox, tbox[i], CIoU=True).squeeze() # iou(prediction, target)
lbox += (1.0 - iou).mean() # iou loss

To answer the original question, you should be able to pull the values from the regression section shown above, and apply the offsets explained in section 4.3 of https://docs.ultralytics.com/yolov5/tutorials/architecture_description#44

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Stale
Projects
None yet
Development

No branches or pull requests

3 participants