Skip to content

[Enhance] Upgrage visualization to custom colors of different classes.#6716

Merged
ZwwWayne merged 28 commits intoopen-mmlab:devfrom
jbwang1997:visualization
Jan 17, 2022
Merged

[Enhance] Upgrage visualization to custom colors of different classes.#6716
ZwwWayne merged 28 commits intoopen-mmlab:devfrom
jbwang1997:visualization

Conversation

@jbwang1997
Copy link
Copy Markdown
Collaborator

Motivation

To custom colors for objects with different classes.
Figure_1

Modification

The main changes are in image.py
I also add a new argument named --show-colors in test.py to custom colors in the command line.

@jbwang1997
Copy link
Copy Markdown
Collaborator Author

When learning visualization in mmdetection, I find the colors are still in the BGR format. It is a legacy of mmcv.visualization. Do you have a plan to update mmcv.visualization.

@ZwwWayne
Copy link
Copy Markdown
Collaborator

Hi @jbwang1997 ,
Thanks for your kind contribution. Could you fix the lint issue?

For now, we do not have a plan to upgrade mmcv.visualization. Do you mean that the arguments in the API implemented in mmdet still use the BGR format as input?

@jbwang1997
Copy link
Copy Markdown
Collaborator Author

I tried to run pre-commit run --all-files, but got an ssl error.
image

Then I run isort mmdet/core/visualization/image.py, but also cannot pass the lint.

@BIGWangYuDong
Copy link
Copy Markdown
Collaborator

You can follow https://mmcv.readthedocs.io/en/latest/community/contributing.html#code-style to prepare pre-commit hook

@jbwang1997
Copy link
Copy Markdown
Collaborator Author

You can follow https://mmcv.readthedocs.io/en/latest/community/contributing.html#code-style to prepare pre-commit hook

I have followed this ,but still reported same error.

tools/test.py Outdated
default=0.3,
help='score threshold (default: 0.3)')
parser.add_argument(
'--show-colors',
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide a simple example to illustrate the usage.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--show-colors can be a single color or a color file.

# single color input
python tools/test.py \
    configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py \
    checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth \
    --show \
    --show-colors green
# single color file
python tools/test.py \
    configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py \
    checkpoints/faster_rcnn_r50_fpn_1x_coco_20200130-047c8118.pth \
    --show \
    --show-colors colors.txt

colors.txt

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not a good way to load colors from txt file

@BIGWangYuDong BIGWangYuDong changed the title Upgrage visualization to custom colors of different classes. [Enhance] Upgrage visualization to custom colors of different classes. Dec 15, 2021
@BIGWangYuDong
Copy link
Copy Markdown
Collaborator

BIGWangYuDong commented Dec 15, 2021

Hi, we have discussed this PR today. Maybe you can follow MMSegmentation, an example: https://github.com/open-mmlab/mmsegmentation/blob/master/mmseg/datasets/coco_stuff.py. You can have a look at MMSeg codes, and use Dataset.PALETTE to set colors.

@jbwang1997
Copy link
Copy Markdown
Collaborator Author

Ok, this is much better than directly setting colors in the command line. I will change the code as soon as possible.

@BIGWangYuDong
Copy link
Copy Markdown
Collaborator

BIGWangYuDong commented Dec 15, 2021

Ok, this is much better than directly setting colors in the command line. I will change the code as soon as possible.

You can follow https://github.com/cocodataset/panopticapi/blob/master/panoptic_coco_categories.json to set labels color

Meanwhile, it is suggested to support random color, if labels are more than given colors.

@jbwang1997
Copy link
Copy Markdown
Collaborator Author

@BIGWangYuDong I have a few questions. The color style in mmsegmentation is RGB. Do I need to change it into BGR to fit the mmcv.color_val or directly use the RGB colors and discard mmcv.color_val.

@BIGWangYuDong
Copy link
Copy Markdown
Collaborator

Please @AronLin have a look

@AronLin
Copy link
Copy Markdown
Contributor

AronLin commented Dec 22, 2021

@BIGWangYuDong I have a few questions. The color style in mmsegmentation is RGB. Do I need to change it into BGR to fit the mmcv.color_val or directly use the RGB colors and discard mmcv.color_val.

We can directly use the RGB format palette.

@jbwang1997
Copy link
Copy Markdown
Collaborator Author

Hello, I have added unit tests in the last commit. For updating the visualization image, could you tell me which image needs to update?

@AronLin AronLin self-requested a review December 30, 2021 05:32
Copy link
Copy Markdown
Contributor

@AronLin AronLin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Copy Markdown
Contributor

@AronLin AronLin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, we should modify the argument coments of imshow_det_bboxes. The color can be list now.

@jbwang1997
Copy link
Copy Markdown
Collaborator Author

I have visualized some results of mask_rcnn_r50_fpn.
visualization4
visualization1
visualization2

@AronLin AronLin requested a review from RangiLyu January 5, 2022 03:21
Comment on lines 212 to 218
def show_result_pyplot(model,
img,
result,
palette=None,
score_thr=0.3,
title='result',
wait_time=0):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid break using positional arguments.

Suggested change
def show_result_pyplot(model,
img,
result,
palette=None,
score_thr=0.3,
title='result',
wait_time=0):
def show_result_pyplot(model,
img,
result,
score_thr=0.3,
title='result',
wait_time=0,
palette=None,):

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your suggestion.

@RangiLyu RangiLyu changed the base branch from master to dev January 17, 2022 03:22
@RangiLyu
Copy link
Copy Markdown
Member

Panoptic visualization is based on this PR. We should merge it asap. Kindly ping @ZwwWayne .

@ZwwWayne ZwwWayne merged commit b6f21e3 into open-mmlab:dev Jan 17, 2022
chhluo pushed a commit to chhluo/mmdetection that referenced this pull request Feb 21, 2022
open-mmlab#6716)

* Update visualization

* Fix a help text mistake

* short function docs

* Fix for iosrt

* Back to master

* Check by pre-commit

* Update dataset_warppers palette

* Custom colors for visualizaton

* Update visualization in image_demo.py

* align palette with panopticapi

* delete palette from checkpoint meta

* Use tuple to represent color

* Update visualization

* Modify image_demo.py

* Check test error

* Check test error

* Fix error for empty case

* Delete redundant functions

* Check visualization

* Add default case

* Fix bug

* Fix bugs

* Add unit tests

* Change coments

* Avoid break using positional arguments.

* Add copyright

* Modify comments

* fix lint

Co-authored-by: Guangchen Lin <347630870@qq.com>
ZwwWayne pushed a commit that referenced this pull request Jul 18, 2022
#6716)

* Update visualization

* Fix a help text mistake

* short function docs

* Fix for iosrt

* Back to master

* Check by pre-commit

* Update dataset_warppers palette

* Custom colors for visualizaton

* Update visualization in image_demo.py

* align palette with panopticapi

* delete palette from checkpoint meta

* Use tuple to represent color

* Update visualization

* Modify image_demo.py

* Check test error

* Check test error

* Fix error for empty case

* Delete redundant functions

* Check visualization

* Add default case

* Fix bug

* Fix bugs

* Add unit tests

* Change coments

* Avoid break using positional arguments.

* Add copyright

* Modify comments

* fix lint

Co-authored-by: Guangchen Lin <347630870@qq.com>
ZwwWayne pushed a commit to ZwwWayne/mmdetection that referenced this pull request Jul 19, 2022
open-mmlab#6716)

* Update visualization

* Fix a help text mistake

* short function docs

* Fix for iosrt

* Back to master

* Check by pre-commit

* Update dataset_warppers palette

* Custom colors for visualizaton

* Update visualization in image_demo.py

* align palette with panopticapi

* delete palette from checkpoint meta

* Use tuple to represent color

* Update visualization

* Modify image_demo.py

* Check test error

* Check test error

* Fix error for empty case

* Delete redundant functions

* Check visualization

* Add default case

* Fix bug

* Fix bugs

* Add unit tests

* Change coments

* Avoid break using positional arguments.

* Add copyright

* Modify comments

* fix lint

Co-authored-by: Guangchen Lin <347630870@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

6 participants