-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Linearly interpolating upsampling fix #5927
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
5bb6ede to
dc579b5
Compare
|
@pytorchbot retest this please |
534a7f6 to
981e339
Compare
|
@pytorchbot retest this please |
|
@Dorimer Let me know if the math formula in this PR looks okay to you. |
aten/src/ATen/nn_parse.py
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
aten/src/ATen/test/basic.cpp
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
test/test_nn.py
Outdated
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
Please come to an agreement about the formulas before merging, thanks! |
Yes, I verified a formula and it looks good. However, I discovered another problem in the new behaviour – it sometimes can produce negative values: https://gist.github.com/Dorimer/899faff586f27070ce55f1cc78c69ce1 with Similar in CUDA code. |
… linearly interpolating modes When align_corners=True, it uses the old original upsampling scheme, which gives visually better results, but doesn't properly align input and output pixels, and thus cause the output vary basing on input. This PR adds this align_corners option, and changes the default behavior to align_corners=False, with proper warning if this option is not specified upon using nn.Upsample or nn.functional.upsample to let be aware of this new change. Adds tests in test_nn.py for spatial invariance when align_corners=False, and usual module tests for align_corners=False.
fdafbd6 to
c249518
Compare
|
@Dorimer @ssnl for what it's worth I have been handling bilinear interpolation by |
* upstream/master: (663 commits) Fix "command not found" error in perf test (pytorch#5982) add pip mkl-devel to the error message when mkl is found but mkl headers are not (pytorch#5984) Support batch LowerCholeskyTransform (pytorch#5980) Linearly interpolating upsampling fix (pytorch#5927) Store perf numbers in S3 (pytorch#5951) Modidy setup docs for Windows (pytorch#5981) Group Normalization (pytorch#5968) [distributions] Implement Power transform (pytorch#5976) Disable TestBottleneck test_cuda on Windows (pytorch#5977) Fix crash when cat-ing empty cuda tensors (pytorch#5971) Update no_unions flag for nanopb gen and update ONNX proto files (pytorch#5972) Expose gradients w.r.t. input & weight for conv1d, conv2d, conv3d in Python (pytorch#5408) Fixed non-determinate preprocessing on DataLoader (pytorch#4640) add AVX2 implementation for sigmoid function (pytorch#5010) Implement torch.util.bottleneck (pytorch#5216) Remove pragma once from cpp file (pytorch#5965) fix mvn docs (pytorch#5967) Fix incorrect rendering of Tensor.index_*_ doc examples. (pytorch#5969) Implement range for loop in script (pytorch#5827) Add windows doc (pytorch#5859) ... # Conflicts: # aten/src/TH/generic/THTensorMath.c # torch/_tensor_docs.py # torch/csrc/generic/methods/TensorCompare.cwrap
Add align_corners option to upsampling module & functional when using linearly interpolating modes:
When align_corners=True, it uses the old original upsampling scheme, which gives visually better results,
but doesn't properly align input and output pixels, and thus cause the output vary basing on input.
This PR adds this align_corners option, and changes the default behavior to align_corners=False, with
proper warning if this option is not specified upon using nn.Upsample or nn.functional.upsample to let
be aware of this new change.
Adds tests in test_nn.py for spatial invariance when align_corners=False, and usual module tests for
align_corners=False.
The ratio is basically computed as:
And src_idx is:
The
0.5are used to cast the index to location of the pixel centers.This also makes the default upsampling behavior consistent with other DL frameworks like tf.
This solves the issue raised in #5511
cc @Dorimer