question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inconsistent representation of box in torchvision.ops

See original GitHub issue

Feature suggestion

When checking the how the new operations in the torchvision 0.11 work, I found an inconsistency between different function.

import torchvision.ops as tops
import torch
import torch.nn as nn

a = torch.zeros(1, 1, 8, 8)
a[..., :4, 4:] = 1
bbox = tops.masks_to_boxes((a==1)[0].float()) 
area = tops.box_area(bbox) # the returned area is 9 which should be 16

new_box = tops.box_convert(bbox, 'xyxy', 'xywh') # which returns [4, 4, 3, 3] => expected output [4, 4, 4, 4]

Suggest a potential alternative/fix

This is not actually an error but could cause confusion.

I suggest to make the box representations between different function more consistent.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:23 (20 by maintainers)

github_iconTop GitHub Comments

1reaction
fmassacommented, Oct 28, 2021

We should return area / sizes as x2 - x1, and not x2 - x1 + 1 as it was previously done in early versions of other libraries (like Detectron).

This was a deliberate decision, and as @rbgirshick pointed out in the past

Anyone interested in this issue should read http://alvyray.com/Memos/CG/Microsoft/6_pixel.pdf. I believe that this provides the correct framework for thinking about continuous geometric entities (e.g., boxes, polygons, etc) and discrete rasterized entities (e.g., bit masks, feature maps, etc.).

1reaction
NicolasHugcommented, Oct 26, 2021

Thanks.

Then I’m not sure this 0 vs 1 indexing discussion is relevant to what we’re concerned with here. Python is 0-based and we’re following that too.

The problem we have here is the relation between x1 - x0 and y1 - y0, and how it plays out in the area calculation, and other conversions. Those concerns are valid whether one uses 0 or 1-based indexing, but I don’t think we should worry about supporting 1-based indexing.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[BUG] Pytorch-> Inconsistent conversion torchvision.ops.nms ...
Hi everyone, I encounter a strange issue. I tried to convert detectron2 RoI Heads, I could convert it to ONNX successfully, but I...
Read more >
torchvision.ops — Torchvision 0.11.0 documentation - PyTorch
'cxcywh' : boxes are represented via centre, width and height, cx, cy being center of box, w, h being width and height. Parameters....
Read more >
torchvision Changelog - pyup.io
torchvision ops are now natively supported by torchscript. This includes operators such ... Fix inconsistent NMS implementation between CPU and CUDA (1556)
Read more >
The Need for Consistency in Object Detection - arXiv
accuracy metrics do not properly account for inconsistency, ... dashed-line box) while the man is detected (green solid box).
Read more >
ReduNet: A White-box Deep Network from the Principle of ...
Keywords: rate reduction, white-box deep network, linear discriminative representation, multi-channel convolution, sparsity and invariance trade-off.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found