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

[Fix] Replace interpolate with resize #731

Merged
merged 3 commits into from Jul 28, 2021
Merged

[Fix] Replace interpolate with resize #731

merged 3 commits into from Jul 28, 2021

Conversation

mmeendez8
Copy link
Contributor

Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily get feedback. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.

Motivation

I am having problems to export mmsegmentation -> onnx -> tensorflow. There is a know limitation related with interpolate (see here). I tried to fix mmseg.ops.resize behavior to always use align_corners but I realize some modules are still using torch F.interpolate.
`

Modification

Use mmseg resize wrapper for all operations.

BC-breaking (Optional)

Does the modification introduce changes that break the backward-compatibility of the downstream repos?
If so, please describe how it breaks the compatibility and how the downstream projects should modify their code to keep compatibility with this PR.

Use cases (Optional)

If this PR introduces a new feature, it is better to list some use cases here, and update the documentation.

Checklist

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit test to ensure the correctness.
  3. If the modification has potential influence on downstream projects, this PR should be tested with downstream projects, like MMDet or MMDet3D.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@CLAassistant
Copy link

CLAassistant commented Jul 27, 2021

CLA assistant check
All committers have signed the CLA.

@mmeendez8
Copy link
Contributor Author

mmeendez8 commented Jul 27, 2021

Just realized my problem was also related with FPN Upsample:

https://github.com/open-mmlab/mmsegmentation/blob/master/mmseg/models/decode_heads/fpn_head.py#L48

I wonder if we should replace this calls with upsample wrapper from ops:
https://github.com/open-mmlab/mmsegmentation/blob/master/mmseg/ops/wrappers.py#L29

@codecov
Copy link

codecov bot commented Jul 27, 2021

Codecov Report

Merging #731 (5d7f09b) into master (6526593) will decrease coverage by 0.02%.
The diff coverage is 85.71%.

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

@@            Coverage Diff             @@
##           master     #731      +/-   ##
==========================================
- Coverage   85.28%   85.26%   -0.03%     
==========================================
  Files         107      107              
  Lines        5817     5822       +5     
  Branches      952      952              
==========================================
+ Hits         4961     4964       +3     
- Misses        673      674       +1     
- Partials      183      184       +1     
Flag Coverage Δ
unittests 85.26% <85.71%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
mmseg/models/backbones/swin.py 86.94% <50.00%> (+0.04%) ⬆️
mmseg/models/necks/fpn.py 54.54% <66.66%> (+0.59%) ⬆️
mmseg/models/backbones/unet.py 94.91% <100.00%> (+0.04%) ⬆️
mmseg/models/backbones/vit.py 84.84% <100.00%> (ø)
mmseg/models/decode_heads/fpn_head.py 100.00% <100.00%> (ø)
mmseg/models/decode_heads/setr_mla_head.py 100.00% <100.00%> (ø)
mmseg/models/decode_heads/setr_up_head.py 100.00% <100.00%> (ø)
mmseg/models/necks/multilevel_neck.py 100.00% <100.00%> (ø)
mmseg/datasets/builder.py 86.84% <0.00%> (-2.64%) ⬇️

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 6526593...acd5ee0. Read the comment docs.

@Junjun2016
Copy link
Collaborator

Hi @mmeendez8
Thanks for your nice PR!

I wonder if we should replace this calls with upsample wrapper from ops:
https://github.com/open-mmlab/mmsegmentation/blob/master/mmseg/ops/wrappers.py#L29

Yes, we can replace it with upsample wrapper.
Update it, please!

@Junjun2016
Copy link
Collaborator

Hi @grimoire and @AllentDan

I am having problems to export mmsegmentation -> onnx -> tensorflow. There is a know limitation related with interpolate (see here). I tried to fix mmseg.ops.resize behavior to always use align_corners but I realize some modules are still using torch F.interpolate.

@mmeendez8
Copy link
Contributor Author

mmeendez8 commented Jul 27, 2021

Hi @grimoire and @AllentDan

I am having problems to export mmsegmentation -> onnx -> tensorflow. There is a know limitation related with interpolate (see here). I tried to fix mmseg.ops.resize behavior to always use align_corners but I realize some modules are still using torch F.interpolate.

Sorry, forgot to say that problem has been fixed. Tensorflow does not support torch.interpolate or torch.upsample when align_corners=False. So I basically fixed mmseg.ops.resizebehavior to always use align_corners=True, that's when I realize there was mixed calls to pytorch and mmseg.ops.

@Junjun2016
Copy link
Collaborator

Hi @grimoire and @AllentDan

I am having problems to export mmsegmentation -> onnx -> tensorflow. There is a know limitation related with interpolate (see here). I tried to fix mmseg.ops.resize behavior to always use align_corners but I realize some modules are still using torch F.interpolate.

Sorry, forgot to say that problem has been fixed. Tensorflow does not support torch.interpolate or torch.upsample when align_corners=False. So I basically fixed mmseg.ops.resizebehavior to always use align_corners, that's when I realize there was mixed calls to pytorch and mmseg.ops.

I see, thanks again!

@Junjun2016
Copy link
Collaborator

@mmeendez8

fixed mmseg.ops.resize behavior to always use align_corners

I am confused about this since he defaults args of resize are the same as F.interpolate.
The default setting of align_corners is None.

@Junjun2016
Copy link
Collaborator

Hi @mmeendez8
Please fix the CI.

@Junjun2016
Copy link
Collaborator

image

Please fix the unittest of test_interp_conv in test_unet.py.

@mmeendez8
Copy link
Contributor Author

Hi @mmeendez8
Please fix the CI.

Yes, sorry. I had already pushed fix

@Junjun2016
Copy link
Collaborator

@mmeendez8

fixed mmseg.ops.resize behavior to always use align_corners

I am confused about this since he defaults args of resize are the same as F.interpolate.
The default setting of align_corners is None.

Could you please explain it?

@Junjun2016
Copy link
Collaborator

Hi @mmeendez8
Please fix the CI.

Yes, sorry. I had already pushed fix

Thanks.

@Junjun2016
Copy link
Collaborator

Junjun2016 commented Jul 27, 2021

@mmeendez8

fixed mmseg.ops.resize behavior to always use align_corners

I am confused about this since he defaults args of resize are the same as F.interpolate.
The default setting of align_corners is None.

Do you mean that set align_corners to True or False instead of None?

@mmeendez8
Copy link
Contributor Author

@mmeendez8

fixed mmseg.ops.resize behavior to always use align_corners

I am confused about this since he defaults args of resize are the same as F.interpolate.
The default setting of align_corners is None.

You mean set align_corners to True or False instead of None?

I meant that I brute force align_corners=True. But I realized that this was not working properly, that's how I discover that nn.interpolate was being called in multiple places. Hope this can clarify it!

@Junjun2016
Copy link
Collaborator

Junjun2016 commented Jul 27, 2021

@mmeendez8

fixed mmseg.ops.resize behavior to always use align_corners

I am confused about this since he defaults args of resize are the same as F.interpolate.
The default setting of align_corners is None.

You mean set align_corners to True or False instead of None?

I meant that I brute force align_corners=True. But I realized that this was not working properly, that's how I discover that nn.interpolate was being called in multiple places. Hope this can clarify it!

Ok, I see, thanks!

@Junjun2016 Junjun2016 changed the title Replace interpolate with resize [Fix] Replace interpolate with resize Jul 28, 2021
Copy link
Collaborator

@Junjun2016 Junjun2016 left a comment

Choose a reason for hiding this comment

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

LGTM

@Junjun2016 Junjun2016 merged commit f800669 into open-mmlab:master Jul 28, 2021
@mmeendez8 mmeendez8 deleted the replace-interpolate-with-ops-resize branch July 28, 2021 15:25
bowenroom pushed a commit to bowenroom/mmsegmentation that referenced this pull request Feb 25, 2022
* Replace interpolate with resize

* Replace nn.Upsample with ops.Upsample

* Fix test
aravind-h-v pushed a commit to aravind-h-v/mmsegmentation that referenced this pull request Mar 27, 2023
…open-mmlab#731)

This is to ensure that the final latent slices stay somewhat consistent as more changes are introduced into the library.

Signed-off-by: James R T <jamestiotio@gmail.com>

Signed-off-by: James R T <jamestiotio@gmail.com>
wjkim81 pushed a commit to wjkim81/mmsegmentation that referenced this pull request Dec 3, 2023
* Add back "registry.py" files with deprecation warnings.

* add unittest for backward compatibility
sibozhang pushed a commit to sibozhang/mmsegmentation that referenced this pull request Mar 22, 2024
* resolve comments

* update changelog

* add Kinetics CN README

* add Kinetics CN README

* move file

* refine
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.

None yet

3 participants