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

[Enhance] Better result visualization #419

Merged
merged 6 commits into from
Aug 31, 2021
Merged

Conversation

mzr1996
Copy link
Member

@mzr1996 mzr1996 commented Aug 19, 2021

Motivation

Now, our show_result_pyplot doesn't support wait_time. And it uses OpenCV as the imshow backend, which may cause some problems, refers to open-mmlab/mmdetection#4389

Modification

Modify the visualization APIs and code structure as mmdet style.

BC-breaking (Optional)

No

Use cases (Optional)

Use demo as example:

python demo/image_demo.py demo/demo.JPEG config/resnet/resnet50_b32x8_imagenet.py resnet50.pth

Previous version demo

result2

Current version demo

result

Checklist

Before PR:

  • Pre-commit or other linting tools are used to fix the potential lint issues.
  • Bug fixes are fully covered by unit tests, the case that causes the bug should be added in the unit tests.
  • The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  • The documentation has been modified accordingly, like docstring or example tutorials.

After PR:

  • If the modification has potential influence on downstream or other related projects, this PR should be tested with those projects, like MMDet or MMSeg.
  • CLA has been signed and all committers have signed the CLA in this PR.

@mzr1996 mzr1996 requested a review from Ezra-Yu August 19, 2021 07:27
@codecov
Copy link

codecov bot commented Aug 19, 2021

Codecov Report

Merging #419 (d130f40) into master (5c4da16) will increase coverage by 0.30%.
The diff coverage is 92.39%.

❗ Current head d130f40 differs from pull request most recent head f0a129d. Consider uploading reports for the commit f0a129d to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##           master     #419      +/-   ##
==========================================
+ Coverage   76.68%   76.98%   +0.30%     
==========================================
  Files          97       99       +2     
  Lines        5216     5271      +55     
  Branches      853      863      +10     
==========================================
+ Hits         4000     4058      +58     
+ Misses       1096     1093       -3     
  Partials      120      120              
Flag Coverage Δ
unittests 76.98% <92.39%> (+0.30%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
mmcls/__init__.py 89.65% <ø> (ø)
mmcls/apis/__init__.py 100.00% <ø> (ø)
mmcls/apis/test.py 24.13% <ø> (ø)
mmcls/apis/train.py 22.72% <ø> (ø)
mmcls/core/__init__.py 100.00% <ø> (ø)
mmcls/core/evaluation/__init__.py 100.00% <ø> (ø)
mmcls/core/evaluation/eval_hooks.py 22.41% <ø> (ø)
mmcls/core/evaluation/eval_metrics.py 80.76% <ø> (ø)
mmcls/core/evaluation/mean_ap.py 100.00% <ø> (ø)
mmcls/core/evaluation/multilabel_eval_metrics.py 100.00% <ø> (ø)
... and 91 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5c4da16...f0a129d. Read the comment docs.

mmcls/apis/inference.py Show resolved Hide resolved
mmcls/core/visualization/image.py Show resolved Hide resolved
plt.show(block=False)
plt.pause(wait_time)
if out_file is not None:
mmcv.imwrite(img, out_file)
Copy link
Collaborator

Choose a reason for hiding this comment

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

mmcv.imwrite(image, out_file, auto_mkdir=True) can suto make a dir if users forget to makedir.

Copy link
Member Author

Choose a reason for hiding this comment

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

The default value of auto_mkdir should be True?

@@ -168,10 +168,11 @@ def val_step(self, data, optimizer):
def show_result(self,
img,
Copy link
Collaborator

Choose a reason for hiding this comment

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

api expresses that img can be a (str or ndarray), but here img can only be the image path.

Copy link
Member Author

Choose a reason for hiding this comment

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

mmcv.imread supports np.ndarray.

@@ -197,27 +198,17 @@ def show_result(self,
img = mmcv.imread(img)
img = img.copy()
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this line is redundant

Copy link
Member Author

Choose a reason for hiding this comment

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

This line prevents this function from modifying the original image.

return tuple(color)


def imshow_cls_result(img,
Copy link
Collaborator

@Ezra-Yu Ezra-Yu Aug 25, 2021

Choose a reason for hiding this comment

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

Can this function be split into two, add_text and mmcls_show.
then in mmcls_show, it may be better to make the backend of img_show, img_show (backend="plt") and img_show (backend="opencv").

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it's not convenient to split. We need to add text after plt.imshow, show argument only determine whether to call plt.show().
And if we have used plt.imshow, backend="cv2" is redundant.

@mzr1996 mzr1996 requested a review from Ezra-Yu August 26, 2021 06:28
Copy link
Collaborator

@Ezra-Yu Ezra-Yu left a comment

Choose a reason for hiding this comment

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

LGTM

@mzr1996 mzr1996 merged commit 5383787 into open-mmlab:master Aug 31, 2021
Ezra-Yu pushed a commit to zhangrui-wolf/mmclassification that referenced this pull request Sep 7, 2021
* Imporve result visualization to support wait time and change the backend
to matplotlib.

* Add unit test for visualization

* Add adaptive dpi function

* Rename `imshow_cls_result` to `imshow_infos`.

* Support str in `imshow_infos`

* Improve docstring.
mzr1996 added a commit that referenced this pull request Sep 29, 2021
* Add RepVGG code.

* Add se_module as plugin.

* Add the repvggA0 primitive config

* Change repvggA0.py to fit mmcls

* Add RepVGG configs

* Add repvgg_to_mmcls

* Add tools/deployment/convert_repvggblock_param_to_deploy.py

* Change configs/repvgg/README.md

* Streamlining the number of configuration files.

* Fix lints

* Delete plugins

* Delete code about plugin.

* Modify the code for using se module.

* Modify config to fit repvgg with se.

* Change se_cfg to allow loading of pre-training parameters.

* Reduce the complexity of the configuration file.

* Finsh unitest for repvgg.

* Fix bug about se in repvgg_to_mmcls.

* Rename convert_repvggblock_param_to_deploy.py to reparameterize_repvgg.py, and delete setting about device.

* test commit

* test commit

* test commit command

* Modify repvgg.py to make the code more readable.

* Add value=0 in F.pad()

* Add se_cfg to arch_settings.

* Fix bug.

* modeify some attr name and Update unit tests

* rename stage_0 to stem and branch_identity to branch_norm

* update unit tests

* add m.eval in unit tests

* [Enhance] Enhence SE layer to support custom squeeze channels. (#417)

* add enhenced SE

* Update

* rm basechannel

* fix docstring

* Update se_layer.py

fix docstring

* [Docs] Add algorithm readme and update meta yml (#418)

* Add README.md for models without checkpoints.

* Update model-index.yml

* Update metafile.yml of seresnet

* [Enhance] Add `hparams` argument in `AutoAugment` and `RandAugment` and some other improvement. (#398)

* Add hparams argument in `AutoAugment` and `RandAugment`.

And `pad_val` supports sequence instead of tuple only.

* Add unit tests for `AutoAugment` and `hparams` in `RandAugment`.

* Use smaller test image to speed up uni tests.

* Use hparams to simplify RandAugment config in swin-transformer.

* Rename augment config name from `pipeline` to `pipelines`.

* Add some commnet ad docstring.

* [Feature] Support classwise weight in losses (#388)

* Add classwise weight in losses:CE,BCE,softBCE

* Update unit test

* rm some extra code

* rm some extra code

* fix broadcast

* fix broadcast

* update unit tests

* use new_tensor

* fix lint

* [Enhance] Better result visualization (#419)

* Imporve result visualization to support wait time and change the backend
to matplotlib.

* Add unit test for visualization

* Add adaptive dpi function

* Rename `imshow_cls_result` to `imshow_infos`.

* Support str in `imshow_infos`

* Improve docstring.

* Bump version to v0.15.0 (#426)

* [CI] Add PyTorch 1.9 and Python 3.9 build workflow, and remove some CI. (#422)

* Add PyTorch 1.9 build workflow, and remove some CI.

* Add Python 3.9 CI

* Show Python 3.9 support.

* [Enhance] Rename the option `--options` in some tools to `--cfg-options`. (#425)

* [Docs] Fix sphinx version (#429)

* [Docs] Add `CITATION.cff` (#428)

* Add CITATION.cff

* Fix typo in setup.py

* Change author in setup.py

* modeify some attr name and Update unit tests

* rename stage_0 to stem and branch_identity to branch_norm

* update unit tests

* add m.eval in unit tests

* Update unit tests

* refactor

* refactor

* Alignment inference accuracy

* Update configs, readme and metafile

* Update readme

* return tuple and fix metafile

* fix unit test

* rm regnet and classifiers changes

* update auto_aug

* update metafile & readme

* use delattr

* rename cfgs

* Update checkpoint url

* Update readme

* Rename config files.

* Update readme and metafile

* add comment

* Update mmcls/models/backbones/repvgg.py

Co-authored-by: Ma Zerun <mzr1996@163.com>

* Update docstring

* Improve docstring.

* Update unittest_testblock

Co-authored-by: Ezra-Yu <1105212286@qq.com>
Co-authored-by: Ma Zerun <mzr1996@163.com>
mzr1996 added a commit to mzr1996/mmpretrain that referenced this pull request Nov 24, 2022
* Imporve result visualization to support wait time and change the backend
to matplotlib.

* Add unit test for visualization

* Add adaptive dpi function

* Rename `imshow_cls_result` to `imshow_infos`.

* Support str in `imshow_infos`

* Improve docstring.
mzr1996 added a commit to mzr1996/mmpretrain that referenced this pull request Nov 24, 2022
* Add RepVGG code.

* Add se_module as plugin.

* Add the repvggA0 primitive config

* Change repvggA0.py to fit mmcls

* Add RepVGG configs

* Add repvgg_to_mmcls

* Add tools/deployment/convert_repvggblock_param_to_deploy.py

* Change configs/repvgg/README.md

* Streamlining the number of configuration files.

* Fix lints

* Delete plugins

* Delete code about plugin.

* Modify the code for using se module.

* Modify config to fit repvgg with se.

* Change se_cfg to allow loading of pre-training parameters.

* Reduce the complexity of the configuration file.

* Finsh unitest for repvgg.

* Fix bug about se in repvgg_to_mmcls.

* Rename convert_repvggblock_param_to_deploy.py to reparameterize_repvgg.py, and delete setting about device.

* test commit

* test commit

* test commit command

* Modify repvgg.py to make the code more readable.

* Add value=0 in F.pad()

* Add se_cfg to arch_settings.

* Fix bug.

* modeify some attr name and Update unit tests

* rename stage_0 to stem and branch_identity to branch_norm

* update unit tests

* add m.eval in unit tests

* [Enhance] Enhence SE layer to support custom squeeze channels. (open-mmlab#417)

* add enhenced SE

* Update

* rm basechannel

* fix docstring

* Update se_layer.py

fix docstring

* [Docs] Add algorithm readme and update meta yml (open-mmlab#418)

* Add README.md for models without checkpoints.

* Update model-index.yml

* Update metafile.yml of seresnet

* [Enhance] Add `hparams` argument in `AutoAugment` and `RandAugment` and some other improvement. (open-mmlab#398)

* Add hparams argument in `AutoAugment` and `RandAugment`.

And `pad_val` supports sequence instead of tuple only.

* Add unit tests for `AutoAugment` and `hparams` in `RandAugment`.

* Use smaller test image to speed up uni tests.

* Use hparams to simplify RandAugment config in swin-transformer.

* Rename augment config name from `pipeline` to `pipelines`.

* Add some commnet ad docstring.

* [Feature] Support classwise weight in losses (open-mmlab#388)

* Add classwise weight in losses:CE,BCE,softBCE

* Update unit test

* rm some extra code

* rm some extra code

* fix broadcast

* fix broadcast

* update unit tests

* use new_tensor

* fix lint

* [Enhance] Better result visualization (open-mmlab#419)

* Imporve result visualization to support wait time and change the backend
to matplotlib.

* Add unit test for visualization

* Add adaptive dpi function

* Rename `imshow_cls_result` to `imshow_infos`.

* Support str in `imshow_infos`

* Improve docstring.

* Bump version to v0.15.0 (open-mmlab#426)

* [CI] Add PyTorch 1.9 and Python 3.9 build workflow, and remove some CI. (open-mmlab#422)

* Add PyTorch 1.9 build workflow, and remove some CI.

* Add Python 3.9 CI

* Show Python 3.9 support.

* [Enhance] Rename the option `--options` in some tools to `--cfg-options`. (open-mmlab#425)

* [Docs] Fix sphinx version (open-mmlab#429)

* [Docs] Add `CITATION.cff` (open-mmlab#428)

* Add CITATION.cff

* Fix typo in setup.py

* Change author in setup.py

* modeify some attr name and Update unit tests

* rename stage_0 to stem and branch_identity to branch_norm

* update unit tests

* add m.eval in unit tests

* Update unit tests

* refactor

* refactor

* Alignment inference accuracy

* Update configs, readme and metafile

* Update readme

* return tuple and fix metafile

* fix unit test

* rm regnet and classifiers changes

* update auto_aug

* update metafile & readme

* use delattr

* rename cfgs

* Update checkpoint url

* Update readme

* Rename config files.

* Update readme and metafile

* add comment

* Update mmcls/models/backbones/repvgg.py

Co-authored-by: Ma Zerun <mzr1996@163.com>

* Update docstring

* Improve docstring.

* Update unittest_testblock

Co-authored-by: Ezra-Yu <1105212286@qq.com>
Co-authored-by: Ma Zerun <mzr1996@163.com>
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

Successfully merging this pull request may close these issues.

2 participants