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

Corners bounding box format #172

Closed
leondgarse opened this issue Mar 17, 2022 · 14 comments
Closed

Corners bounding box format #172

leondgarse opened this issue Mar 17, 2022 · 14 comments

Comments

@leondgarse
Copy link

leondgarse commented Mar 17, 2022

I got an issue when trying to port two of my currently using bounding box augment related functions resize_and_crop_bboxes and bboxes_apply_affine. I think we better set a default expecting bbox input format. For my usage, the corner bounding box is in same format with tfds COCO, that I think is [top, left, bottom, right] with value in range [0, 1].

import tensorflow_datasets as tfds
ds, info = tfds.load('coco/2017', with_info=True)
aa = ds['train'].as_numpy_iterator().next()
print(aa['image'].shape)
# (462, 640, 3)
print(aa['objects'])
# {'area': array([17821, 16942,  4344]),
#  'bbox': array([[0.54380953, 0.13464062, 0.98651516, 0.33742186],
#         [0.50707793, 0.517875  , 0.8044805 , 0.891125  ],
#         [0.3264935 , 0.36971876, 0.65203464, 0.4431875 ]], dtype=float32),
#  'id': array([152282, 155195, 185150]),
#  'is_crowd': array([False, False, False]),
#  'label': array([3, 3, 0])}

imm = aa['image']
plt.imshow(imm)

for bb in aa["objects"]["bbox"]:
    bb = np.array([bb[0] * imm.shape[0], bb[1] * imm.shape[1], bb[2] * imm.shape[0], bb[3] * imm.shape[1]])
    plt.plot(bb[[1, 1, 3, 3, 1]], bb[[0, 2, 2, 0, 0]])

Figure_1

It will save some effort checking format if we can set a standard. So my questions are:

  • Currently in bounding_box.py, we are assuming it's LEFT, TOP, RIGHT, BOTTOM. Are we gonna set this as default?
  • Is value range expecting in [0, 1] or scaled with image actual shape?
@innat
Copy link
Contributor

innat commented Mar 17, 2022

Similar query: #21 (comment)

@leondgarse
Copy link
Author

Right, close this then.

@innat
Copy link
Contributor

innat commented Mar 17, 2022

@leondgarse no, you don't need to close, I didn't mean that. You should re-open it.

( I just mentioned that I've asked a similar query as a comment there but sadly still no response from the keras team. Maybe they didn't decide yet. )

@leondgarse leondgarse reopened this Mar 17, 2022
@leondgarse
Copy link
Author

Ya, personally, I cannot move on without a clarify. :)

@innat
Copy link
Contributor

innat commented Mar 17, 2022

same here.

@LukeWood
Copy link
Contributor

My instinct is that corners format makes the most sense as it is a denser format. Any thoughts?

@bhack
Copy link
Contributor

bhack commented Mar 21, 2022

Could be a bounding box a specialized type of a bounding polygon that it could be also more precise aproximation of a segmentation mask? See cocodataset/cocoapi#131

@LukeWood
Copy link
Contributor

LukeWood commented Mar 21, 2022

Could be a bounding box a specialized type of a bounding polygon that it could be also more precise aproximation of a segmentation mask? See cocodataset/cocoapi#131

I think we want to special case bounding boxes and explicitly support them.

@leondgarse
Copy link
Author

My option is strict the input / output format of these bbox augment functions. Other not matching format or segmentation mask should be transformed before calling these functions. It can also benefit further anchor / anchor assign / detection lossses, that we don't need to consider other format.

@qlzh727
Copy link
Member

qlzh727 commented Mar 23, 2022

  1. Currently I don';t think we assume any default format for bbox, but I think we should have one default format (probably the corner bbox format).
  2. I don't think we should normalized the bbox value to [0, 1], otherwise it will require the original image to decode the actual pixel.

@bhack
Copy link
Contributor

bhack commented Mar 23, 2022

@qlzh727
Copy link
Member

qlzh727 commented Mar 23, 2022

Thanks for the context, will take a look.

@LukeWood
Copy link
Contributor

LukeWood commented Apr 7, 2022

I think @qlzh727 and I have decided to move forward with corners format as the default. This is XYWH with true pixel values.

If there is a strong reason to deviate, please let us know and we can reconsider.

@leondgarse
Copy link
Author

Ya, it's good for me. Will close this issue then.

freedomtan pushed a commit to freedomtan/keras-cv that referenced this issue Jul 20, 2023
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

No branches or pull requests

5 participants