-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Random colors for draw_bounding_boxes #4658
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
Conversation
Hi @ABD-01 I don't think so the error you mentioned might be valid, CI failures don't point to that. I think you need to update the expected image, in the assets. A simple way is to delete the existing images, and re-run the pytest. Apart from that can you just have a trial run like an example from our gallery and post the outputs here? Edit: |
Also
Do you think we will ever hit color is None here in fill? we can just remove these lines I guess? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also need to add to docstring.
By default, random colors are generated for boxes. If labels are provided, boxes with same labels have same color.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ABD-01 and @oke-aditya for the review. This looks great, I just have one minor comment below. The ones from @oke-aditya above are also relevant :)
Looks like some related tests are failing, would you mind taking a look?
Also, since these things are hard to test, would you mind providing a few visual examples of images with boxes illustrating the new color palette in use?
Thanks!
When we pass colors ourselves: boxes = torch.tensor([[50, 50, 100, 200], [210, 150, 350, 430], [150, 30, 900, 650]], dtype=torch.float)
colors = ["blue", "yellow", "red"]
result = draw_bounding_boxes(dog1_int, boxes, colors=colors, width=8)
show(result) When boxes = torch.tensor([[50, 50, 100, 200], [210, 150, 350, 430], [150, 30, 900, 650]], dtype=torch.float)
result = draw_bounding_boxes(dog1_int, boxes, width=8)
show(result) When we pass labels: boxes = torch.tensor([[50, 50, 100, 200], [210, 150, 350, 430], [150, 30, 900, 650]], dtype=torch.float)
labels = ["box1", "box2", "box3"]
result = draw_bounding_boxes(dog1_int, boxes, labels=labels, width=8)
show(result) What if labels are repeated: boxes = torch.tensor([[210, 150, 350, 430], [50, 50, 100, 200], [150, 30, 900, 650]], dtype=torch.float)
labels = ["box1", "box2", "box1"]
result = draw_bounding_boxes(dog1_int, boxes, labels=labels, width=8)
show(result) The image is attached with the respective code snippets. |
Yes Sure. Looks like we gave the expected image to look like this: But now we are asking it to make boxes of different color, so it will look like this: |
The test will be flaky if we expect to check if a randomly generated image matches the same image. So we have to pass colors to the function while testing. The logic looks to be working fine, as we are getting consistent colors for boxes with same label. I am bit busy this week. I will have a run and check why the green color is getting preferred. Edit: |
To generate a A Tensor containing random RGB colors
We can modify generate_color_palette and make it generate random colors. Can you have a go with these modifications @ABD-01 ? |
let's just pass |
colors = _generate_color_palette(len(img_boxes)) | ||
else: | ||
assert len(labels) == len(img_boxes) | ||
label_color_map = dict(zip(labels, _generate_color_palette(len(labels)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since now we agree that len(labels) == len(img_boxes) Line 207 and 204 can be simplified.
Closing in favour of #5127 |
Hi!
This pr is with reference to #4528
I have made the changes for generating random colors from the palette for bounding boxes.
But I am not getting why the tests are failing for the following cases even before the changes are done.
i.e. it is not accepting
colors="red"
orcolors="#FF00FF"
as valid inputsThanks to @oke-aditya for pseudocode.